bsamson Posted November 14, 2006 Share Posted November 14, 2006 Here's the situation. I have the following code:[code]<div class="stacked"> <div class="basicBox"> <h2>Customer Information</h2> <br /> <table width="100%" border="1" cellpadding="0" cellspacing="0" class="confirmForm tighter"> <tr> <td class="label">Phone Number:</td> <td class="data">123-456-7890</td> </tr> <tr> <td class="label">First Name:</td> <td class="data">GEORGE</td> </tr> <tr> <td class="label">Last Name:</td> <td class="data">JOHNSON</td> </tr> </table> <div class="hrTight"></div> <h2>Phone Upgrade Program Results</h2> <div class="hrTight"></div> <div id="rebtable"> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <th class="headborder">Savings Amount</th> <th> Eligibility Date</th> </tr> <tr> <td class="displaycell"> Up to $75 with a two-year subscriber agreement<br> (or up to $25 with a one-year agreement) </td> <td>06/01/2006</td> </tr> <tr><td colspan="2"><hr width="100%"/></td></tr> <tr> <td class="displaycell"> Up to $150 with a two-year subscriber agreement<br> (or up to $75 with a one-year agreement) </td> <td>04/01/2007</td> </tr> </table> </div>[/code]Now, I am attempting to grab some info from this page with this:[code]$result=(THE PAGE W/ THE ABOVE CODE)$regex = "/<td class=\"label\">Phone Number:<\/td>.*?<td class=\"data\">(.*?)<\/td>.*?<td class=\"label\">First Name:<\/td>.*?<td class=\"data\">(.*?)<\/td>.*?<td class=\"label\">Last Name:<\/td>.*?<td class=\"data\">(.*?)<\/td>.*?<td>([0-9]{2}\/[0-9]{2}\/[0-9]{4})<\/td>.*?<td>([0-9]{2}\/[0-9]{2}\/[0-9]{4})<\/td>/is";preg_match_all($regex, $result, $matches);$phno = $matches[1][0];$first = $matches[2][0];$last = $matches[3][0];$oneyr = $matches[4][0];$twoyr = $matches[5][0];[/code]Could I please get some help figuring out why $phno, and $first are not storing the info I need? Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/27230-issue-grabbing-info-w-regex/ Share on other sites More sharing options...
Orio Posted November 14, 2006 Share Posted November 14, 2006 bsamson, I already replied to you on the other thread you opened:http://www.phpfreaks.com/forums/index.php/topic,114413.msg467895.html#msg467895Orio. Link to comment https://forums.phpfreaks.com/topic/27230-issue-grabbing-info-w-regex/#findComment-124540 Share on other sites More sharing options...
Nicklas Posted November 14, 2006 Share Posted November 14, 2006 To optimize your pattern, you can do something like this:[code=php:0]preg_match_all('~(?<=data">).*?(?=<)|\d{2}/\d{2}/\d{4}~is', $result, $matches);list($phno, $first, $last, $oneyr, $twoyr) = $matches[0];[/code] Link to comment https://forums.phpfreaks.com/topic/27230-issue-grabbing-info-w-regex/#findComment-124562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.