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;
}
//Example:
str_prefix('test', 3, '-') => returns '---test'<br/>str_suffix('test', 3, '-') => returns 'test---'<br/>
Url: http://www.jonasjohn.de/snippets/php/prefix-and-suffix.htm
Language: PHP | User: ShareMySnippets | Created: Oct 16, 2013