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 Link to comment https://forums.phpfreaks.com/topic/207672-function-print-outside-div/ 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), '*'); } Link to comment https://forums.phpfreaks.com/topic/207672-function-print-outside-div/#findComment-1085631 Share on other sites More sharing options...
MuseiKaze Posted July 14, 2010 Author Share Posted July 14, 2010 oh lol. my bad, thanks Link to comment https://forums.phpfreaks.com/topic/207672-function-print-outside-div/#findComment-1085633 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)); } Link to comment https://forums.phpfreaks.com/topic/207672-function-print-outside-div/#findComment-1085634 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.