Jump to content

[SOLVED] To get phone number from datas.


chanchelkumar

Recommended Posts

Hi friends,

 

I have a bunch of variables, one for each of our employees. Included in these variables are phone numbers: work phone in format (XXX) XXXXXXX etc. How can I write a script that searches for and extracts the phone numbers from these variables?

Link to comment
https://forums.phpfreaks.com/topic/81325-solved-to-get-phone-number-from-datas/
Share on other sites

Ok...

 

suppose

 

$check="front street Unique historical building Office Space - 1925 square foot + Call xxx-xxx-xxxx (18 Nov 2007) (xxx) xxxxxxx, - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

 

this value is coming from database table....

 

and i want to take this phone number from that varible...

 

i tried with preg_match...

 

 

$US_PHONE_PREG ="/^(?:\+?1[\-\s]?)?(\(\d{3}\)|\d{3})[\-\s\.]?"; //area code
    $US_PHONE_PREG.="(\d{3})[\-\.]?(\d{4})/"; // seven digits
preg_match($US_PHONE_PREG,$check, $matches);
echo "</br>";
echo $matches[1];

 

it returns me no value...

 

 

Based on your data set:

 

<pre>
<?php
$data = 'front street Unique historical building Office Space - 1925 square foot + Call xxx-xxx-xxxx (18 Nov 2007) (xxx) xxxxxxx, - xxxxxxxxxxxxxxx';
preg_match_all('/
	\(?\d{3}\)?
	\D?
	\d{3}
	\D?
	\d{4}
/x', $data, $matches);
print_r($matches);
?>
</pre>

 

Tip: Avoid being excessive in smilies (:):(;):D) and punctuation?!?!. It's unnecessary.

Normally we don't provide full code examples without some work from you.  Unless you don't know anything about PHP, we're here to help you when you get stuck with the code, not write it for you.

 

Also, please be careful about using personal/work information about locations and/or phone numbers in the future.  I've removed all the references from the thread.  It may not bother you, but others could use the information in a malicious manner.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.