Hi,

I was wondering if anyone can see why the substr_replace() function isn't replacing the 'XXXXX' with the random integer I am creating in the script below:

<?php
	$password = rand(12345,98765);
	$stringtoparse = 'Your new password is XXXXX';
	substr_replace($stringtoparse,$password,18);
	echo $stringtoparse;
?>

When I run this, I still have the following being output:

Your new password is XXXXX

Can anyone see why the function wouldn't be working as I expect and replace the XXXXX with the random number being generated?

Many thanks for any help!

:)

Recommended Answers

All 2 Replies

Why do you have to use replace?
Cant you just append the random password to the and of the string without XXXXX ?
Like this

<?php
$password = rand(12345,98765);
$stringtoparse = 'Your new password is ' . $password;
echo $stringtoparse;
?>
commented: Thanks for the help :) +2

Edit: Didn't read the previous post and said the same thing

commented: Thanks for the help :) +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.