$from= "You can win $200,000 tonight.";
$output = preg_match("/'$['d',]+/", $from, $matches);
echo $matches[0];
这是不工作。它给了我这个错误:
注意:未定义偏移量:0
我想输出"$200,000"。
感谢您的帮助。
try
$output = preg_match("/''$['d',]+/", $from, $matches);
你必须用双引号'
转义两次$符号http://ideone.com/digsP你用正则表达式的双引号把自己打到了膝盖上。试试这个:
$from= "You can win $200,000 tonight.";
if(preg_match("/'$['d',]+/", $from, $matches)) {
echo $matches[0];
}
你看,没有匹配。您必须转义两次,一次用于字符串,一次用于正则表达式引擎:
$from= "You can win $200,000 tonight.";
if(preg_match("/'''$['d',]+/", $from, $matches)) {
echo $matches[0];
}
HTH,CK
转义$两次
$output = preg_match("/''$['d',]+/", $from, $matches);