Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP正则表达式中的esping引号_Php_Regex_Quotes - Fatal编程技术网

PHP正则表达式中的esping引号

PHP正则表达式中的esping引号,php,regex,quotes,Php,Regex,Quotes,如何在以下字符串($x)中仅找到电话号码(1234827382) 重要提示:我在$x(文本)上使用了htmlspecialchars()函数。如果不使用此函数,正则表达式可以工作。在正则表达式之前使用htmlspecialchars()时,我需要找到正则表达式解决方案。 font-size: 14px; color: #333;" >asd:</td> <td width="150" align="left" valig

如何在以下字符串($x)中仅找到电话号码(1234827382)

重要提示:我在
$x
(文本)上使用了
htmlspecialchars()
函数。如果不使用此函数,正则表达式可以工作。在正则表达式之前使用
htmlspecialchars()
时,我需要找到正则表达式解决方案。

 font-size: 14px; color: #333;" >asd:</td> <td width="150" align="left" valign="top"
    bgcolor="#f5f5f5" style="padding: 6px; border: 1px solid
    #eaeaea;font-family: Arial, Helvetica, sans-serif; font-size: 14px; color:
    #333;" >Tel:</td> <td align="left" valign="top" style="padding: 6px;
    border: 1px solid #eaeaea;font-family: Arial, Helvetica, sans-serif;
    font-size: 14px; color: #333;" ><a href="tel:1234827382">1234827382</a></td> </tr>
<tr> <td width="150" align="left"
如果我尝试使用\逃逸,那么它也不起作用:

$p = '/href=\"tel:12.{20}/';

如果文本不包含引号:则需要使用反斜杠转义引号

就您的情况而言,
/href=\“电话:12.{20}/


编辑:如果使用
htmlspecialchars($x)
,引号
将变为
,因此您需要将正则表达式更新为
/href=“tel:12.{20}/

,如果您的情况是数字没有任何特殊字符,则可以使用以下方法:

$p = '/\d{10}/';
preg_match_all($p, $x, $matchestel);
print_r($matchestel);

这是我第一次尝试的,但没有成功。请看。。。它在这里返回子字符串,所以我猜问题出在代码的其他部分。是的,代码工作正常。我忘了提到我在$x上使用了htmlspecialchars@约翰:这是重要的信息。好的,更新了我的答案。您没有捕获组
()
:ex:
”/href=“tel:([0-9]+)”/”
()。但是使用XML解析器应该更准确。不,在正则表达式替换之后使用
htmlspecialchars
$p = '/\d{10}/';
preg_match_all($p, $x, $matchestel);
print_r($matchestel);