Ok so Im selecting some scraped text from my db and trying to parse for the phone number. Its in there and Im not getting any errors but the var_dump
is returning int 0
Why? Here's the code
$query1 = "SELECT adtext, `key` FROM usedcars WHERE `key` = $x";
mysqli_query($conn, $query1);
$link_result = mysqli_query($conn, $query1);
$result = mysqli_fetch_assoc($link_result);
//now parse that number
$phone_number = preg_match("/^((([0-9]{1})*[- .(]*([0-9]{3})[- .)]*[0-9]{3}[- .]*[0-9]{4})+)*$/", $result['adtext']);
var_dump($phone_number);
}
Btw, this is a part of a loop that iterates through each rowin the db. Like I said, its not throwing an error, just not recognizing the number so I think maybe there is something wrong with the regex or idk. Here is the particular text its preg_match
-ing
2001 Ford POS in great condition but definitely Im a liar and it will break down before you get home. Fix.Or.Repair.Daily that what I always say<br>
<br>
NO Blocked Calls<br>
<br>
I AM IN WASHINGTON D.C / VIRGINIA / MARYLAND Local buyers only<br>
<br>
<b>No warranty</b><br>Forsale by owner<br>
<br>
<b>Accepting first offer</b>
<b>24 hours call <u><b>Call Me ☎ 202-510-5939</b></b></u>
</div>
<p class="metaInfoDisplay">Poster's Reputation: 0<br></p>
<div style="padding-left:2em;">
• Location:
Northern Virginia, ☎ 202-210-5936
</div>
<div style="padding-left:2em;"><br />• Post ID: 1234567 washingtondc</div>
<div id="OtherAdsByThisUser" data-oid="7654321">
Help a slow guy out please!
([0-9]?[- .(]*[0-9]{3}[- .)][0-9]{3}[- .][0-9]{4})
Didn't exactly understand your regex but you can try this.More testing would be required though.Try here.
http://regex101.com/r/lZ5mN8/1
Your regex will not work because of the anchors ^
and &
. They will match the start and end of the line. I have removed them and modified your regex.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.