Please I hope someone can help me ... I cannot figure this one out ...
Here's the situation. I work for a small Sprint Dealer, and Sprint has a retention program in place. With that once a customer has the same phone for 1 year, they get a $75 Discount, and if they have it 2 years they get upto a $150 Discount.
Now, with cURL and PHP I am attempting to grab that info off sprints site and display it within our intranet. Below is the code for the page ...
MAIN.PHP
<?
// cURL : Grab page store in $html
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://pcshandsetupgrade.sprint.com/info.php?from=index.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "phoneNumber=2520000000&zipCode=90210");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$html = curl_exec ($ch);
curl_close ($ch);
//echo $html;
// Regular Expression to grab customer information
$regex = "/<td class="label">Sprint PCS 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);
$num = $matches[1][0];
$first = $matches[2][0];
$last = $matches[3][0];
$oneyr = $matches[4][0];
$twoyr = $matches[5][0];
echo $num; echo "<br>";
echo $first; echo "<br>";
echo $last; echo "<br>";
echo $oneyr; echo "<br>";
echo $twoyr; echo "<br>";
?>
Please note, I have replaced the original working phone # and zip code with other values. When I view this page nothing gets displayed ... and I am absolutely stumped. I am not sure if it is a problem w/ cURL or the RegEX as I am a new to both.
Now here's the kicker .... I made another page as a test, called test.php. Here is the source of that page ....
TEST.PHP
<?
// cURL : Grab page store in $html
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://pcshandsetupgrade.sprint.com/info.php?from=index.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "phoneNumber=2520000000&zipCode=90210");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$html = curl_exec ($ch);
curl_close ($ch);
echo $html;
When I view the TEST.PHP page all is well and the page is displayed .... HOWEVER, as soon as I view the MAIN.PHP page and attempt to echo $html, it shows a blank page. It almost seems as if $html gets cleared when I run MAIN.PHP. Please any suggestions would be GREATLY APPRECIATED!