Click to See Complete Forum and Search --> : Replacing a string with asterix's


copes
10-22-2007, 08:19 AM
Hi there,

i'm currently trying to replace all the characters in a password string with asterix's as to show the password length but not reveal the actual password.

i'm having some difficulty understanding how to use ereg_replace

this is the current code im trying:

$password = ereg_replace("[^a-z, A-Z, 0-9]"," ",$row['password']);

but i could be completely wrong about how the function works. could anyone give me some pointers? i've had a look at the function description on php.net but i didn't really understand it.

Thanks

aj_nsc
10-22-2007, 08:26 AM
why don't you just use strlen (http://ca.php.net/strlen)?

Kostas Zotos
10-22-2007, 12:53 PM
Hi,

Maybe a different approach:
You can use inside HTML (If this is the case) the standard "input" with the "type" set to "password".. like:
<input type="password" name="password" id="password" size=8 maxlength=32>
This ( on the contrary with <input type="text" .. > ) by default displays asterisks no matter what the input text is..

If you prefer a regex approach could be (I used a preg regular expression) :
$password = $row['password'];
$password = preg_replace("/./", "*", $password); // The dot "." represents any character (except new lines, as it is now)

Kostas