截取某个字符之前的字符串
// 如下为截取 "-" 字符前的字符串
$str = "hello-world";
$new_string = substr( $str, 0, strrpos($str, '-') );
echo $new_string; // 输出 "hello"
字符串替换
php替换多个字符串 str_replace 函数,可以传入要删除替换的字符串
echo str_replace(array("m","i"), array("n","z"), "my name is jim!")
echo str_replace(array('m', 'i'), 'n', "my name is jim!");
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U"); $onlyconsonants = str_replace($vowels, "", "Hello World of PHP"); echo $onlyconsonants;
反转字符串
strrev( $string )
返回 string
反转后的字符串。