Home >Backend Development >PHP Tutorial >求一行正则表达式,哪位能帮帮忙?

求一行正则表达式,哪位能帮帮忙?

WBOY
WBOYOriginal
2016-06-06 20:48:551138browse

求一行正则表达式,哪位能帮帮忙?

准备在这个软件里用

如果含有 “问答”、“百度”、"搜索" 这三个词当中的任意一个或几个,就把这几个词提取出来,并用逗号隔开

回复内容:

求一行正则表达式,哪位能帮帮忙?

准备在这个软件里用

如果含有 “问答”、“百度”、"搜索" 这三个词当中的任意一个或几个,就把这几个词提取出来,并用逗号隔开

<code class="lang-php"><?php preg_match_all('#(问答|百度|搜索)#ius','如果含有"问答"、"百度"、...',$matches);
print_r($matches[1]); //Array ( [0] => 问答 [1] => 百度 )
echo implode(',', $matches[1]); //问答,百度
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn