steveclondon Posted February 5, 2007 Share Posted February 5, 2007 Hi, I want to be able to remove phone numbers from postings on a website. I do not want to remove other numbers such as prices. I would perhaps want to test how long the number is to see if it is lightly that it is a phone number and allow for spaces such as in the example. I would also leave numbers if they have a decimal point in them perhaps. 44 01233 555 555 Any ideas of the best way to go about this. Quote Link to comment Share on other sites More sharing options...
effigy Posted February 5, 2007 Share Posted February 5, 2007 How serious of a task is this? I ask because there are many ways to get around it. Below is an example that provides a specific and less-specific approach. Do you need to support different phone formats? <pre> <?php $tests = array( '44 01233 555 555', '44-01233-555-555', '44.01233.555.555', '4401233555555', ); // $separator = '[-. ]?'; // ...or, less specific: $separator = '\D?'; foreach ($tests as $test) { echo $test, ' => '; $test = preg_replace("/ \d{2} $separator \d{5} $separator \d{3} $separator \d{3} /x", '', $test); echo $test, '<br>'; } ?> </pre> Quote Link to comment Share on other sites More sharing options...
steveclondon Posted February 8, 2007 Author Share Posted February 8, 2007 Hi It needs to be able to remove all phone numbers for different countrys so they could start with different codes and be slightly different lenghts with either spaces between or other forms of seperators. However at the same time a user will give price information that will normally be up to 5 to 6 digits such as 5000 or 10000 but could at most 9 if it includes a decimal point. What I really want to do is count how many numbers are together without a decimal point and then if there are more than 6 numbers in a row without a decimal point that is two characters at the end before a space, assume this is a phone number and take it out, this could be with a space or a - inbetween(i do understand that there might be situations where this could be a problem such as if someone said "1000 - 2000 USD", but im ok with that). I don't know if you follow all that. Im ok with php programming but haven't had that much regex experiance yet so any help is greatly appreached. I also currently have a regex taking out all combinations of email address however I would also like to know if anyone has a regex that takes out common things people do to try and get around this. like "me at hotmail dot com". anyway I know thats alot in there. Quote Link to comment Share on other sites More sharing options...
effigy Posted February 8, 2007 Share Posted February 8, 2007 This could be challenging, but before going forward I want to reiterate and determine how important this task is. The reason I ask is, once phone numbers are eliminated, what prevents a user from typing "six three one..." or even "sechs drei eins..." (German)? Quote Link to comment Share on other sites More sharing options...
steveclondon Posted February 12, 2007 Author Share Posted February 12, 2007 true must admit i didn't think of that (must be having an off day here) however i have now written the code to remove phone numbers but leave in in numbers such as 1000.00 or 1000. Im sure its not perfect but here it is "/([\(\+])?([0-9]{1,3}([\s])?)?([\+|\(|\-|\)|\s])?([0-9]{3,4})([\-|\)|\.|\s]([\s])?)?([0-9]{2,4})?([\.|\-|\s])?([0-9]{4,8})/","/\b()\b/i" Would like to know what you all think Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.