Ultimate way to find phone numbers in PHP string with preg_replace

前端 未结 4 1839
无人及你
无人及你 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:23

    I guess this might do it for these cases?

    preg_replace("/(\+?[\d-\(\)\s]{7,}?\d)/", 'number', $str);
    

    Basicly I check if it may start on +. It doesn't have to. Then I check if it got numbers, -, (, ) and spaces with at least 8 cases so it doesn't pick low non-phone numbers.

提交回复
热议问题