<?php
set_time_limit(100);
//error_reporting(E_ALL);
extract($_REQUEST);
$keywords = "";
$keywords1 = "w";
if (isset($submit)) {
$list1 = explode(",", $input1);
$list2 = explode(",", $input2);
foreach ($list1 as $word1) {
foreach ($list2 as $word2) {
$keywords = $keywords . "\n" . $prefix .
trim($word1) . " " .
trim($word2) . " ";
$keywords1 = $keywords1 . "\n" . $prefix .
trim($word2) . " " .
trim($word1) . " ";
$keyws[] = $word1 . ' ' . $word2;
$keyws[] = $word2 . ' ' . $word1;
}
}
$keywords .= $keywords1;
$urlelements = array();
foreach ($keyws as $k => $v) {
$urlelements = explode(' ', $v);
$url = 'http://www.google.com/search?q=';
foreach ($urlelements as $k2 => $v2) {
$url .= $v2 . '+';
}
$url .= '&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official"';
$urls[] = $url;
}
//TO VIEW CREATED URLS UNCOMMENT THIS
//foreach ($urls as $key => $value) {
// echo $value . "<br>";
//}
//exit();
echo "<pre>\n"; // IMPROVE READABILITY
//
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>Position</th>";
echo "<th>Domain</th>";
echo "<th>Phone</th></tr>";
foreach ($urls as $u){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
$file=curl_exec ($ch) or die(curl_error());
curl_close ($ch);
// CREATE AN ARRAY FROM THE HTML-----------------------------1. Domain
$arr = explode('</a></h4><cite>', $file);
// DISCARD THE UNWANTED STUFF AT THE TOP OF THE HTML
unset($arr[0]);
// TIDY UP EACH ELEMENT OF THE ARRAY
foreach ($arr as $ptr => $string)
{
// LOCATE THE END OF USEFUL DATA
$poz = strpos($string, '</cite> - <nobr>');
// END OF DATA NOT FOUND - SKIP THIS ELEMENT
if ($poz === FALSE)
{
unset($arr[$ptr]);
continue;
}
// REMOVE USELESS TRAILING DATA AND REPAIR HTML (XML) ENTITIES
$arr[$ptr] = substr($string, 0, $poz);
$arr[$ptr] = str_replace('&', '&', $arr[$ptr]);
}
// CREATE AN ARRAY FROM THE HTML-----------------------------2. Phone Number
$arr2 = explode('</cite> - <nobr>', $file);
// DISCARD THE UNWANTED STUFF AT THE TOP OF THE HTML
unset($arr2[0]);
// TIDY UP EACH ELEMENT OF THE ARRAY
foreach ($arr2 as $ptr => $string2)
{
// LOCATE THE END OF USEFUL DATA
$poz = strpos($string2, '</nobr> - <a class=fl href');
// END OF DATA NOT FOUND - SKIP THIS ELEMENT
if ($poz === FALSE)
{
unset($arr2[$ptr]);
continue;
}
// REMOVE USELESS TRAILING DATA AND REPAIR HTML (XML) ENTITIES
$arr2[$ptr] = substr($string2, 0, $poz);
$arr2[$ptr] = str_replace('&', '&', $arr2[$ptr]);
}
// ACTIVATE THIS TO SEE THE ARRAY
// var_dump($arr);
//CJ set up the table
//Put results in a table
// $newarr = array_combine($keyws, $arr);
for($i=1; $i<=count($arr); $i++){
echo "<tr><td>";
echo $i;
echo "</td><td>";
echo $arr[$i];
echo "</td><td>";
echo $arr2[$i];
echo "</td></tr>";
}
}
echo "</table>";
}else{
echo "<form id='' action='" . $_SERVER['PHP_SELF'] ."' method='post'>";
echo "<table>";
echo "<tr>";
echo "<td><input type='text' id='' name='input1' value='' /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><input type='text' id='' name='input2' value='' /></td>";
echo "</tr>";
echo "<tr>";
echo "<td><input type='submit' id='' name='submit' value='submit' /></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}
?>
|