brendan6 Posted November 12, 2007 Share Posted November 12, 2007 im looking for a function that will create a string of a certain character a specified number of times. ex. $newstring = unknownfunction("*",5) //resulting in $newstring being ***** NOTE: I know how to create a loop to do this, just wondering if such a function exists. Quote Link to comment Share on other sites More sharing options...
Branden Wagner Posted November 12, 2007 Share Posted November 12, 2007 Im pretty sure there isnt one.. but you can do one pretty quick check http://us2.php.net/strings to see if you got it. function repeat($string,$number) { $output= ''; for($i=0;$i==$number; $i++) { $output .= $string; } return $output } Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 12, 2007 Share Posted November 12, 2007 Here is a working version of your function <?php function repeat($string,$number){ $output= ''; for($i=0;$i<$number; $i++){ $output .= $string; } return $output; } echo repeat('*', 1); ?> Quote Link to comment Share on other sites More sharing options...
brendan6 Posted November 12, 2007 Author Share Posted November 12, 2007 thanks! 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.