$string = 'hello world php is a bla bla..';
如何通过查找字符串是否包含任何"is"来保留"hello world php",然后删除其后的所有字符?
我不能使用 substr,因为"is"的出现不一致,也可能是可重复的。如何抓住第一个?
您可以使用 explode:
<?php
$string = 'hello world php is a bla bla..';
$string = explode(' is ', $string);
echo $string[0];
?>
阅读更多:
http://php.net/manual/en/function.explode.php
尝试这样,
$string = 'hello world php is a bla bla..';
$str= substr($string, 0, strpos($string, "is"));
你也可以使用preg_replace,
$str = preg_replace('/ is.*/', '', $string );