Php 无法输出带有echo的正则表达式数组。注意:未定义的偏移量:0。如何修复它?
这是行不通的。它给了我这个错误: 注意:未定义的偏移量:0 我想输出“200000美元” 提前感谢您的帮助。试试看Php 无法输出带有echo的正则表达式数组。注意:未定义的偏移量:0。如何修复它?,php,regex,preg-match,Php,Regex,Preg Match,这是行不通的。它给了我这个错误: 注意:未定义的偏移量:0 我想输出“200000美元” 提前感谢您的帮助。试试看 $from= "You can win $200,000 tonight."; $output = preg_match("/\$[\d\,]+/", $from, $matches); echo $matches[0]; 您必须用double转义$symbol的两倍\ 试试看 $from= "You can win $200,000 tonight."; $output = p
$from= "You can win $200,000 tonight.";
$output = preg_match("/\$[\d\,]+/", $from, $matches);
echo $matches[0];
您必须用double转义$symbol的两倍\
试试看
$from= "You can win $200,000 tonight.";
$output = preg_match("/\$[\d\,]+/", $from, $matches);
echo $matches[0];
您必须用double转义$symbol的两倍\
只要逃过两次$
$output = preg_match("/\\$[\d\,]+/", $from, $matches);
只要逃过两次
$output = preg_match("/\\$[\d\,]+/", $from, $matches);
你用regex的双引号射中了自己的膝盖。试试这个:
$output = preg_match("/\\$[\d\,]+/", $from, $matches);
你看,没有对手。必须转义两次,一次用于字符串,一次用于正则表达式引擎:
$from= "You can win $200,000 tonight.";
if(preg_match("/\$[\d\,]+/", $from, $matches)) {
echo $matches[0];
}
嗯,,
CK你用正则表达式的双引号把自己射到膝盖上。试试这个:
$output = preg_match("/\\$[\d\,]+/", $from, $matches);
你看,没有对手。必须转义两次,一次用于字符串,一次用于正则表达式引擎:
$from= "You can win $200,000 tonight.";
if(preg_match("/\$[\d\,]+/", $from, $matches)) {
echo $matches[0];
}
嗯,,
CK或直接切换到使用单引号
“/(\$[\d,]+)/”
并添加捕获组()
,以便在$matches中添加内容。$matches始终包含整个匹配,而不考虑反向引用。或者只需切换到使用单引号“/(\$[\d,]+)/”
并添加捕获组()
,这样就可以进入$matches了。$matches始终由整个匹配组成,而不考虑后面的引用。