Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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调用正则表达式以提取电话号码_Php_Regex_Email_Preg Match_Phone Number - Fatal编程技术网

PHP调用正则表达式以提取电话号码

PHP调用正则表达式以提取电话号码,php,regex,email,preg-match,phone-number,Php,Regex,Email,Preg Match,Phone Number,在这里,我试图从电子邮件中提取电话号码 </tr> <tr> <td height=3D"20" valign=3D"bottom" style=3D"font-s= ize:10px; color:#817f80;padding:0px;margin:0px;">1-877-435-2623 | Mo

在这里,我试图从电子邮件中提取电话号码

                        </tr>
                        <tr>
                            <td height=3D"20" valign=3D"bottom" style=3D"font-s=
    ize:10px; color:#817f80;padding:0px;margin:0px;">1-877-435-2623 | Mon-Fri 8=
    am-5pm, Sat-Sun 8am-12pm PST</td>
                        </tr>
                        <tr>
                            <td height=3D"35" valign=3D"bottom" style=3D"font-s=
    ize:10px; margin:0px; margin-top: 10px; padding:0px; padding-bottom:0px; co=
    lor:#939393;">&copy; 2012 Elance, Inc. |  441 Logue Ave. Suite 150 | Mounta=
    in View, CA 94043</td>
                        </tr>
                        <tr>
                            <td height=3D"20" valign=3D"bottom" style=3D"font-s=
    ize:10px; margin:0px; margin-bottom:25px; padding:0px; color:#939393;"><a h=
    ref=3D"https://www.elance.com/q/legal"><span style=3D"color:#939393;text-de=
    coration:none;">Terms of Service</span></a> | <a href=3D"https://www.elance=
    .com/p/legal/privacy-policy.pdf"><span style=3D"color:#939393;text-decorati=
    on:none;">Privacy Policy</span></a> | All Rights Reserved.</td>
                        </tr>
                    </table>
                    <div style=3D"margin: 0; padding: 0;">
                        <a href=3D"http://www.facebook.com/elance"><img src=3D"=
    https://www.elance.com/images/4.0/referral/facebook-btn-16x16.png" border=
    =3D"0" alt=3D"Facebook" title=3D"Facebook" /></a>&nbsp;
                        <a href=3D"http://www.twitter.com/elance"><img src=3D"h=
    ttps://www.elance.com/images/4.0/referral/twitter-btn-16x16.png" border=3D"=
    0" alt=3D"Twitter" title=3D"Twitter" /></a>&nbsp;
                        <a href=3D"http://www.linkedin.com/company/elance"><img=
     src=3D"https://www.elance.com/images/4.0/nav/nav_logo_sprite/icon-li.gif" =
    border=3D"0" alt=3D"LinkedIn" title=3D"LinkedIn" /></a>&nbsp;
                        <a href=3D"http://www.youtube.com/elance"><img src=3D"h=
    ttps://www.elance.com/images/4.0/nav/nav_logo_sprite/icon-yt.gif" border=3D=
    "0" alt=3D"Youtube" title=3D"Youtube" /></a>
                    </div>
                </td>0345-5407008
345-5124587
124-541-2215
+92-3455412412
3251452114
009124125413
hello world its my no. 03005134012
            </tr>

            </tbody>
        </table>

    </DIV>

    </BODY>
    </HTML>




    --PHP-alt-3fbbc9acbecd103566642de6249238ea--

    --PHP-mixed-3fbbc9acbecd103566642de6249238ea--


    251254125
但是 我想忽略在这些字符串中找到的匹配项

--PHP-alt-3fbbc9acbecd103566642de6249238ea--

--PHP-mixed-3fbbc9acbecd103566642de6249238ea--
试一试 有更好的正则表达式吗?
对我的正则表达式的解释:
?(\d|\+)(\+\d|\(\124;\)-| | \){7,25}?


  • 仅当检测到空间或未检测到空间时,开始捕捉编号
  • 如果第一个为0-9或+匹配(+|\d |(|)|-|中的任何字符,则开始匹配
  • 7,25,因为电话号码的最小长度是7和
  • 最多25个左右,包括空格和-等

  • 尝试使用一些单词边界
    \b

    (?:\b\d|\+)(?:\+|\d|\(|\)|-| |\.){7,25}\b
    
    我把捕获组变成了非捕获组。如果你只需要整个数字,我认为你不需要捕获组

    \b
    在“单词”字符后跟“非单词”字符时匹配,反之亦然(即
    \w\w
    \w\w


    .

    尝试使用一些单词边界
    \b

    (?:\b\d|\+)(?:\+|\d|\(|\)|-| |\.){7,25}\b
    
    我把捕获组变成了非捕获组。如果你只需要整个数字,我认为你不需要捕获组

    \b
    在“单词”字符后跟“非单词”字符时匹配,反之亦然(即
    \w\w
    \w\w


    .

    “仅当检测到空格或未检测到空格时,才开始捕获号码”难道这不都是字符吗?事实上,当电话号码位于字符串和空格之间时,当电话号码位于字符串的开头时,才没有空格。您可以通过“/?/”开始捕获号码。当检测到空格或非空格时,这不是所有字符吗?实际上不是,当电话号码位于字符串之间,然后是空格,当电话号码位于字符串开头,则没有空格。您可以通过“/”进行处理