Ultimate way to find phone numbers in PHP string with preg_replace

前端 未结 4 1823
无人及你
无人及你 2020-12-21 21:35

working on a project right now where we have large amount of text strings that we must localize phone numbers and make them clickable for android phones.

The phone n

4条回答
  •  借酒劲吻你
    2020-12-21 22:04

    Perhaps something like this:

    /(\+\d+)?\s*(\(\d+\))?([\s-]?\d+)+/
    
    • (\+\d+)? = A "+" followed by one or more digits (optional)
    • \s* = Any number of space characters (optional)
    • (\(\d+\))? = A "(" followed by one or more digits followed by ")" (optional)
    • ([\s-]?\d+)+ = One or more set of digits, optionally preceded by a space or dash

    To be honest, though, I doubt that you'll find a one-expression-to-rule-them-all. Telephone numbers can be in so many different formats that it's probably impractical to match any possible format with no false positives or negatives.

提交回复
热议问题