Home  >  Article  >  Backend Development  >  php 截取指定的字符串解决方案

php 截取指定的字符串解决方案

WBOY
WBOYOriginal
2016-06-13 12:52:47882browse

php 截取指定的字符串
$a="s=/Toupiao/yulan/pid=117&title=2&selectform=1"有这样一个字符串,我想获取当中pid的值,因为pid值是不定长的,有时会pid=1,pid=12,pid=123......,那我要如何才可以截取pid的值了?

php 截取 字符串
------解决方案--------------------
$a = "s=/Toupiao/yulan/pid=117&title=2&selectform=1";<br />
preg_match('/\bpid=(\d+)/', $a, $r);<br />
echo $r[1];
117
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