Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.