-1

Regex seems to be my kryptonite.

How do I convert:

ereg_replace('[^0-9]+','',str_replace("+", "00", $number))

to:

preg([something])

Coming from: http://james.cridland.net/code/format_uk_phonenumbers.html Id tried changing the first parameter to /[^0-9]+ and `/[^0-9]+/, as well as both of those sans-quotes, but none worked. I'm afraid I'm a regex newbie.

Bing
  • 3,071
  • 6
  • 42
  • 81
  • [Meta] Perhaps I don't understand stackoverflow -- why the downvotes to this question? – Bing Apr 10 '15 at 09:40
  • ^ Maybe a few people missing your effort, you don't show any effort/attempts in your question to solve the problem yourself! (You will get an upV from my side if you show your attempts and effort you have done, before just asking other people to just write your code) – Rizier123 Apr 10 '15 at 09:50

2 Answers2

1

You need to include the php delimiters inside the pattern part for preg_replace():

preg_replace('~[^0-9]+~', '', str_replace("+", "00", $number));
            //^       ^
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • 1
    I think someone just has a bad day :) You're answer is absolutely correct! (Hope you don't mind, just added the links to the references in the manual) – Rizier123 Apr 10 '15 at 09:37
0

Try this:

preg_replace("/[^[:alpha:][:space:]]+/ui", '', str_replace("+", "00", $number));

Coming from this question.

Character classes can be found here: https://php.net/manual/en/regexp.reference.character-classes.php

Community
  • 1
  • 1
Marco Bernardini
  • 695
  • 6
  • 17