这可能很简单,但我找不到它.
我需要在字符串中搜索一组中文字符,并用英文单词替换它们.
所以基本上搜索字符串的第一个字符不是a-z,1-9或 – ,但我找不到如何.
我目前在字符的开头和结尾使用字符串指针来实现结果,工作很好,但看起来很草率.
$str_start = strpos ( $switcher , 'start' );// get the string start
$str_start +=5;//Add 5 to it to make up for the length of search term
$str_end = strpos ( $switcher , '/' , $str_start );//find the end
$length = $str_end - $str_start;//get the length of chinese characters
echo substr_replace ( $switcher , 'product-category' , $str_start , $length );//replace with english word
编辑:为清晰起见添加了实际示例:
English
应该:
English
码:
$str_start = strpos ( $switcher , '.info/' );
$str_start +=6;
$str_end = strpos ( $switcher , '/' , $str_start );
$length = $str_end - $str_start;//get the length of chinese characters
echo substr_replace ( $switcher , 'product-category' , $str_start , $length );