【发布时间】:2015-05-24 15:26:24
【问题描述】:
如果我想检查字符串中是否存在“php”并删除它后面的单词,我可以使用:
$string = 'hello world php is a bla bla..';
$string = explode(' php ', $string);
echo $string[0];
但是如果我有多个单词而不仅仅是 'php' 怎么办?例如下面的几首歌曲名称有'feats','feat','ft','ft.'..这是其中的四个。
我想让“sia - elastic feat brunos mars”变成“sia - elastic”。
【问题讨论】:
-
试试
str_replace('php', '' ,$string) -
@NarendraSisodia 通过使用 explode 我可以做同样的事情,但是多个单词呢?我不想写重复的代码。
标签: php arrays string substring