This article describes how to add a specified number of characters before and after a string by using php. it involves php string-related skills and is very useful, for more information about how to add a specified number of characters before and after a string in php, see the following example. Share it with you for your reference. The specific analysis is as follows:
This php code defines two functions: str_prefix and str_suffix, which are used to add a specified number of symbols before and after the string.
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 'Str _ suffix ('test', 3,'-') => returns 'test ---'
I hope this article will help you with php programming.