Prefix and suffix
Prefixes or suffixes a string with n times char
function str_prefix($str, $n=1, $char=" "){ for ($x=0;$x<$n;$x++){ $str = $char . $str; } return $str; } function str_suffix($str, $n=1, $char=" "){ for ($x=0;$x<$n;$x++){ $str = $str . $char; } return $str; }
Author:
Jonas John
License:
Public Domain
Language:
PHP
Created:
03/28/2006
Updated:
03/28/2006
Tags:
string functions
str_prefix('test', 3, '-') => returns '---test'<br/>str_suffix('test', 3, '-') => returns 'test---'<br/>
Sorry folks, comments have been deactivated for now due to the large amount of spam.
Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!
Older comments:
return str_repeat($char, $n) . $str;
}