Home  >  Article  >  Backend Development  >  php字符串怎么截取

php字符串怎么截取

WBOY
WBOYOriginal
2016-06-13 12:53:40730browse

php字符串如何截取
假设有一个字符串
$addr='甘肃省兰州市电信'
我想取出其中的省和市信息
$p='甘肃省'
$c='兰州市'
怎么操作才能取出?

注:我使用$p = strstr($addr, '省',true); 提示没有第三个参数
有没有其他办法取


------解决方案--------------------
$addr = '甘肃省兰州市电信';
preg_match_all('/.+?(?:省
------解决方案--------------------
市)/', $addr, $r);
list($p, $c) = $r[0];
echo $p;
echo $c;
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