Jump to content

[SOLVED] To get phone number from datas.


chanchelkumar

Recommended Posts

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.