$str = 'http://www.fyj.com/index.php?action=xxxx&name=fyj';
$pattern = "/(?<=action=).+?(?=&)/ims";
preg_match_all($pattern, $str, $matches);
print_r($matches);
$pattern = "/(?<=action=).+?(?=&)/ims";
preg_match_all($pattern, $str, $matches);
print_r($matches);
如果,&name=fyj不一定有呢,那正则的怎么改呀?
谢谢
$pattern = "/(?<=action=).+?(?=&|$)/ims";
preg_match_all($pattern, $str, $matches);
print_r($matches);
试下这个,(?=&|$)表示遇到&或字符串末尾终止。