PHP 如何在一个正则表达式里使用变量?

$star='a';
$stop='c';
$info='a1b2c3';
preg_match('$star(.+?)$stop',$info,$result);
print_r($result[1]);

int preg_match ( string $pattern , string $subject [, array $matches [, int $flags ]] )
string $pattern 是一个字符串,所以可以先计算出这个串存入一个变量里
$star='a';
$stop='c';
$info='a1b2c3';
$pattern='/'.$star.'(.+?)'.$stop.'/';
preg_match($pattern,$info,$result);
print_r($result[1]);
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-18
$star='a';
$stop='c';
$info='a1b2c3';
preg_match('/'.“$star”.'(.+?)'.“$stop”.'/',$info,$result);
print_r($result[1]);
第2个回答  2011-06-20
从变化中找到不变的地方,然后通过正则匹配操作如果 全部是 变化的 毫无规律的 貌似没有办法采集吧?。。
相似回答