Home >Backend Development >PHP Tutorial >正则表达式,超级简单!

正则表达式,超级简单!

WBOY
WBOYOriginal
2016-06-13 11:57:551032browse

求一个正则表达式,超级简单!!!
例子: 沈家门饭店 - 普陀老车站 - 海珍苑 - 海洋生物园区 - 平阳浦 - 浦西公园(共9站)  
比如关键字是生物,得到的数据是海洋生物园区;关键字是公园,得到的是浦西公园;也就是说会给出一个关键字,得到的是杠杠以外或者括号以外的数据不要,求大神帮帮忙
------解决方案--------------------
假定你的字符集是 utf-8

$s = '沈家门饭店 - 普陀老车站 - 海珍苑 - 海洋生物园区 - 平阳浦 - 浦西公园(共9站)';<br />$k = '生物';<br />$k = '公园';<br />preg_match("/\w*$k\w*/u", $s, $r);<br />echo $r[0];

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