MuseiKaze Posted July 14, 2010 Share Posted July 14, 2010 Hey guys. Ive been working on a setup page which will install a few things and I've been having some problems with this function I created. It seems to print out under the <body> tag up the top even though I have it in a print statement inside a <div> tag. All of the text shows up where its ment to but the asterix's dont want to appear there. This is the function, its just ment to put an asterix where the password is. function asterix($pass){ $asterix = 0; $length = strlen($pass); while ($asterix < $length){ print '*'; $asterix++; } } I wont type the whole print statement cause its fairly big, but its pretty much like this. print '<div class="setup"><table><tr><td>Password: ' . asterix($_SESSION['password']) . '</td></tr></table></div>'; What am I missing that would cause it to not print in the right place? Thanks heaps Quote Link to comment Share on other sites More sharing options...
trq Posted July 14, 2010 Share Posted July 14, 2010 Your using it within a print statement yet your function itself prints. make your function return your value instead. It can also be written a little better. function asterix($string) { return str_pad('', strlen($string), '*'); } Quote Link to comment Share on other sites More sharing options...
MuseiKaze Posted July 14, 2010 Author Share Posted July 14, 2010 oh lol. my bad, thanks Quote Link to comment Share on other sites More sharing options...
trq Posted July 14, 2010 Share Posted July 14, 2010 Or better still.... function asterix($string) { return str_repeat("*", strlen($string)); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.