我需要删除任何字符串中的所有字符,然后在字符串中出现这种情况:
"www/audio"
不知道我该怎么做。
You can use strstr to do this.
echo strstr($str, 'www/audio');
You can use substring and strpos to accomplish this goal.
You could also use a regular expression to pattern match only what you want. Your mileage may vary on which of these approaches makes more sense.
Considering
$string="We have www/audio path where the audio files are stored"; //Considering the string like this
Either you can use
strstr($string, 'www/audio');
Or
$expStr=explode("www/audio",$string); $resultString="www/audio".$expStr[1];
I use this functions
function strright($str, $separator) { if (intval($separator)) { return substr($str, -$separator); } elseif ($separator === 0) { return $str; } else { $strpos = strpos($str, $separator); if ($strpos === false) { return $str; } else { return substr($str, -$strpos + 1); } } } function strleft($str, $separator) { if (intval($separator)) { return substr($str, 0, $separator); } elseif ($separator === 0) { return $str; } else { $strpos = strpos($str, $separator); if ($strpos === false) { return $str; } else { return substr($str, 0, $strpos); } } }