Hello,
I hope someone can help me solve this:
I am writing a script which can extract phone numbers from a peice of entered text which i can do fine but when there are other numbers it becomes more complex and i cannot seem to find away round it. All the numbers are not necessarily using the correct format, which i can easily sort once i have got the phone number. A few example numbers are:
111%111%1112
[11.1,11-1-11.12]
111 (111) 1112
An example of the text is:
Phone 111 (111) 1112 to get this for 75% off - Call Now. Offer open to 5pm only full price after 5.
Ofcourse some are longer and contain more numbers than that. Can anyone help me figure out how to fix this?
6 Replies - 4419 Views - Last Post: 16 October 2011 - 01:45 AM
#1
Extracting a phone number from a string with other numbers
Posted 15 October 2011 - 06:40 AM
Replies To: Extracting a phone number from a string with other numbers
#2
Re: Extracting a phone number from a string with other numbers
Posted 15 October 2011 - 08:34 AM
Are you familiar with Regular Expressions? You could build a regular expression to help you out with extracting the phone numbers.
#3
Re: Extracting a phone number from a string with other numbers
Posted 15 October 2011 - 08:35 AM
#4
Re: Extracting a phone number from a string with other numbers
Posted 15 October 2011 - 09:22 AM
What I am wanting to find out is the regex needed to do this is someone can help
#5
Re: Extracting a phone number from a string with other numbers
Posted 15 October 2011 - 09:50 AM
I'm not that familiar with Regular Expressions. However, you may find supercorey's Regex Tutorial helpful.
#6
Re: Extracting a phone number from a string with other numbers
Posted 15 October 2011 - 11:23 AM
Still cannot seem to work it out, has anyone else got some suggestions?
This is what i have now
Any more suggestions?
This is what i have now
<?php
$d = file_get_contents("numbers.txt");
$m = explode("==============================================================================================",$d);
foreach($m as $m1){
echo $m1;
echo "<br><br>";
// This gets it down so it only displays the numbers and spaces
$m2 = preg_replace("/[^0-9\s]/", "", $m1);
echo $m2."<br>";
// After a bit of searching this regex seems to be one to use but no result
preg_match_all('/\b[0-9]{3}\s*[-]?\s*[0-9]{3}\s*[-]?\s*[0-9]{4}\b/',$m1,$matches);
print_r($matches);
echo "<hr>";
}
?>
Any more suggestions?
#7
Re: Extracting a phone number from a string with other numbers
Posted 16 October 2011 - 01:45 AM
Thanks everyone for their suggestions, I have now found away of doing it and with a bit more validation have been able to get it working
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|