函数结构:
string trim ( string $str [, string $character_mask = " \t\n\r\0\x0B" ] )
第一个参数是咱要处理的字符串,第二个参数是要排除的字符(默认 \t\n\r\0\x0B)
函数结构:
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
解释起来太麻烦,我们来看实例:
$str1 = str_replace(‘%name%‘, ‘LargerK‘, ‘my name is %name%‘); echo $str1; // 输出 my name is LargerK
$str1 = str_replace([‘s‘, ‘a‘, ‘t‘], ‘111‘, ‘this is an apple‘); echo $str1; // 输出 111hi111 i111 111n 111pple
$str1 = str_replace(["KFC", "可乐", "薯条"], ["披萨", "酥皮汤", "西冷牛排"], ‘我想吃KFC 点个薯条和可乐‘); echo $str1; // 我想吃披萨 点个西冷牛排和酥皮汤
$count = 0; $str1 = str_replace("oo", "~~", "ooop good... so cool", $count); echo $str1 . "<br />"; // 输出~~op g~~d... so c~~l echo $count; // 输出 3
原文:http://www.cnblogs.com/sun-kang/p/7643467.html