Tuesday 15 February 2011

php - Concerning Using preg_replace() -


For the purpose of testing, this is the code that I am using on my regular expression: < Pre> & lt ;? Php function handphone ($ p) {return preg_replace ("[^ 0- 9xX \ +]", "", $ p); } Echo handphone ("+ 44 (324) -123-32 yukek 42x123"); ? & Gt;

Now, all the printing is the exact string such that no changes were made, why any ideas?

You should finally use delimiter and start your pattern, for example / :

  function handlephone ($ p) {return preg_replace ("/ [^ 0- 9xX \ +] /", "", $ p); }   

Note that you can use other delimiter: ~ # @ . .

No comments:

Post a Comment