bsamson Posted November 9, 2006 Share Posted November 9, 2006 Hello, I am currently working on an internal site for a wireless dealer. We have an upgrade program in place. The carrier offers a site to check a customers upgrade eligibility. On the page it gives the customers name, phone number, 1 yr upgrade date, and 2 yr upgrade date. Along w/ an "Office Use #" at the bottom. Now, in order to pull up this page we have to enter the customers phone # and zip code. I was wondering if their is a way to "grab" those values from that page w/ php? Any help would be greatly appreciated! Thanks! Quote Link to comment Share on other sites More sharing options...
trq Posted November 9, 2006 Share Posted November 9, 2006 Of course there is. Grab the file using [url=http://php.net/file_get_contents]file_get_contents[/url], then you'll need to parse the file for the infomation. If your real lucky the file might be valid xhtml and you should be able to use the [url=http://php.net/simplexml]simpleXML[/url] extension to get what you want, otherwise, you'll need to do quite a bit of work with regular expressions. Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 9, 2006 Author Share Posted November 9, 2006 thank you. I did some reading on it. Now, one more question.there are 2 pages on the carriers site. There is index.php which is where the form resides asking for the customers phone # and zip code. Once that data is entered on that page you are sent to the info.php page, which if everything was entered correctly displays that things i listed above. How in the world in php do I submit the info to the info.php, and then use file_get_contents to get the data. Any suggestions would be GREATLY appreciated!Best Regards,Brian Quote Link to comment Share on other sites More sharing options...
Orio Posted November 9, 2006 Share Posted November 9, 2006 You should look into [url=http://www.php.net/curl]cURL[/url] for that.Orio. Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 9, 2006 Author Share Posted November 9, 2006 Thank you. Are their any scripters on this forum that could quote me a price to code this? Please let me know, thanks. Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 11, 2006 Author Share Posted November 11, 2006 UPDATE. I finially figured out how to grab the page w/ cURL. Now I have the page stored in [i]$result[/i]. You said above that I would have to use regular expressions to get the info I need. I just need a bit of advice ...I need to pull some info off the page ...I need the customer cell phone #, first name, last name, 1st upgrade date, and 2nd upgrade date. Now after looking at the source this is what I noticed:#1: The Phone #, First Name, and Last time all begin with the <td class="data"> tag and ofcourse end with the </td> tag.#2: The 1st and 2nd upgrade dates begin w/ <td> and both end with </td>.Can I please get some help on the regular expressions I will need to pull this info and put them in a variable? Thanks in advance for all your help! Quote Link to comment Share on other sites More sharing options...
Orio Posted November 11, 2006 Share Posted November 11, 2006 Can you paste an example of the source?Orio. Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 11, 2006 Author Share Posted November 11, 2006 Sure! And thank you for the reply.[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> // This line is the phone # <td class="data">123-456-7890</td> </tr> <tr> <td class="label">First Name:</td> // This line is the first name <td class="data">GEORGE</td> </tr> <tr> <td class="label">Last Name:</td> // This line is the last name <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> // This line is the 1st yr upgrade date <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> // This line is the 2nd yr upgrade date <td>04/01/2007</td> </tr> </table> </div>[/code]Thank you for any help! Quote Link to comment Share on other sites More sharing options...
Orio Posted November 11, 2006 Share Posted November 11, 2006 [code]<?php//$html holds the value recived using cURL$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, $html, $matches);?>[/code]$matches[1][0] will contain the phone number.$matches[2][0] will contain the first name.$matches[3][0] will contain the last name.$matches[4][0] will contain the first date.$matches[5][0] will contain the second date.if there are there's more than one result per page, the next result will be in $matches[1][1] (phone), $matches[2][1] (name) etc'Orio. Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 11, 2006 Author Share Posted November 11, 2006 Thank you! Sorry I havent written back sooner, but I have been testing ... Let me show the source of the php script page:[code]<?$ch = curl_init();curl_setopt($ch, CURLOPT_URL,"http://thewebsite.com/info.php?from=index.php");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, "phoneNumber=3956458546&zipCode=78956");curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);$result = curl_exec ($ch);curl_close ($ch); $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);$no = $matches[1][0];$first = $matches[2][0];$last = $matches[3][0];$oneyr = $matches[4][0];$twoyr = $matches[5][0];echo $no;echo $first;echo $last;echo $oneyr;echo $twoyr;?>[/code] Now, when I run this script it just displays a blank page. Any Ideas? Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 12, 2006 Author Share Posted November 12, 2006 bump Quote Link to comment Share on other sites More sharing options...
Orio Posted November 12, 2006 Share Posted November 12, 2006 Because the information you entered (the zip code and the phone number) give:"Please Check Information- The subscriber was not found. Please verify the phone number and zip code and re-enter.".Enter a valid combination.Orio. Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 13, 2006 Author Share Posted November 13, 2006 Thanks. However, keep in mind I did not want to post a real phone # and zip code. With that said the combination I use works on the page ... it's just that my code above doesnt display the info. Any Suggestions, thanks! Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 14, 2006 Author Share Posted November 14, 2006 bump Quote Link to comment Share on other sites More sharing options...
Orio Posted November 14, 2006 Share Posted November 14, 2006 I tested it, and it works fine on my end.See links here to the [url=http://www.oriosriddle.com/html.txt]HTML[/url] you gave me, and [url=http://www.oriosriddle.com/test.php]the result[/url] of running this:[code]<?php$html = file_get_contents("html.txt");$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, $html, $matches);$no = $matches[1][0];$first = $matches[2][0];$last = $matches[3][0];$oneyr = $matches[4][0];$twoyr = $matches[5][0];echo $no; echo "<br>";echo $first; echo "<br>";echo $last; echo "<br>";echo $oneyr; echo "<br>";echo $twoyr; echo "<br>";?>[/code]Orio. Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 14, 2006 Author Share Posted November 14, 2006 Orio, May I PM you a link? Thanks!THANKS! Quote Link to comment Share on other sites More sharing options...
Orio Posted November 14, 2006 Share Posted November 14, 2006 Sure.Orio. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.