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. Link to comment https://forums.phpfreaks.com/topic/77060-solved-insert-character-specified-number-of-times/ 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 } Link to comment https://forums.phpfreaks.com/topic/77060-solved-insert-character-specified-number-of-times/#findComment-390254 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); ?> Link to comment https://forums.phpfreaks.com/topic/77060-solved-insert-character-specified-number-of-times/#findComment-390258 Share on other sites More sharing options...
brendan6 Posted November 12, 2007 Author Share Posted November 12, 2007 thanks! Link to comment https://forums.phpfreaks.com/topic/77060-solved-insert-character-specified-number-of-times/#findComment-390264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.