Remove Phone number from string in PHP

后端 未结 3 1684
迷失自我
迷失自我 2020-12-22 02:23

i want to remove phone number with follow match

one two three four five six seven eight nine zero

i have tried following

相关标签:
3条回答
  • 2020-12-22 03:19

    At the risk of teaching a man to fish...

    I swear by regexbuddy when crafting regex patterns. They have a library of patterns for phone numbers as well. It's really easy to build a pattern and see its result. It's a swiss army knife for programming. I've used it for 7 years and it's always open on my computer.

    Also, it can generate php code (as well as javascript, etc.) for a number of different scenarios.

    0 讨论(0)
  • 2020-12-22 03:20

    I'm not totally sure what you're trying to do, but to start, you define $regexp, but then reference $number_regexp

    0 讨论(0)
  • 2020-12-22 03:23

    Check your regexp variable name

    $regexp = "/[one|two|three|four|five|six|seven|eight|zero]{4,}/";
    $message = preg_replace($regexp, 'XXX', $message);
    

    For number 0 to 9

    preg_replace("/[^0-9]/","",$message);
    

    Use \d if you want to remove all digits

    $message  = preg_replace('/\d/', '', $message);
    

    Or [^a-z\s] if you want to replace all except alphabets and whitespaces

    $message = preg_replace('/[^a-z\s]/i', '', $message);
    
    0 讨论(0)
提交回复
热议问题