[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.8

PHP looping through urls and displaying results in row wtih url

Asked by chrisj1963 in PHP Scripting Language

Hi,
I have 2 scripts that I am trying to combine, but am struggling with how.

The first script generates a list of urls and displays them in rows in a table.
(This is the script at the top of the code below)
here is what it looks like when it runs: http://70.87.107.194/~g3crmco/deny-GoogleRank.php?keyword=pond&url=http%3A%2F%2Fwww.aire-dynamics.com&Submit=Submit

The second script provides the ranking for a given search term for a given url.
(This is the second script listed below)
here is what it looks like when it runs: http://70.87.107.194/~g3crmco/googleserps.php

I would like the result of the second script to appear between the <td></td> as indicated in the first script.   I would like those results to pull the url from

I would like to have the result that is generated in the second script to be incorporated into the first and would like it to use the urls generated and the keyword from script one instead of the fixed url and  keyword (list) from the second.

Does that make sense?

Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
<!--First Script-->
 
<?php
error_reporting(E_ALL ^ E_NOTICE);
//prevents script from timing out
set_time_limit(0);
 
 
 
 
//for POST request with curl
function do_post_request_curl($url, $data)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
    curl_setopt($ch, CURLOPT_POST, 1); // set POST method
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // add POST fields
    $result = curl_exec($ch); // run the whole process
    //echo $result;
    curl_close($ch);
    return $result;
}
 
function file_get_contents_curl($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
    curl_setopt($ch, CURLOPT_URL, $url);
    $data = curl_exec($ch);
    curl_close($ch);
 
    return $data;
}
function getUrl ($sel_keyword) {
	$arrLinks=array();
	$cnt=0;
	
 	$url = 'http://www.google.com/search?hl=en&q='.urlencode($sel_keyword).'&btnG=Google+Search&aq=f&oq=';
	$str = "'".file_get_contents($url)."'";
 
    $h1count = preg_match_all('/\<li class=g\>\<h3 class=r\>\<a href="(.*?)" class=l\>/',$str,$patterns);
 
    $href_add = $patterns[1];
 
 
    if(!empty($href_add[0]))
    {
        foreach($href_add as $key => $val)
        {
        $val = preg_replace("/</","&lt;a",$val);
            //echo "<li>" . htmlentities($val) . "</li>";
            $arrLinks[$cnt]=htmlentities($val);
            ++$cnt;
			//number of urls code CJ
            if($cnt==1)
            {
				break;
            }
 
        }
        echo "</ul>";
    }
	return $arrLinks;
}
?>
 
<!--<?php include('includes/header.php');?>-->
 
<body>
<form id="form1" name="form1" method="get" action="">
  KEYWORD:
	<input name="keyword" type="text" id="keyword" value="<?php echo $_REQUEST['keyword']; ?>" />
  URL :
  	<input name="url" type="text" size="30" id="url" value="<?php echo $_REQUEST['url']; ?>" />
  	<input type="submit" name="Submit" value="Submit" />
  	<br>
  <br>
</form>
<?php
	if ((isset($_REQUEST['Submit'])) && ($_REQUEST['url']!='')) {
?>
<fieldset>
<legend>Query result</legend>
<?php
	$urlarray = array();
 
	$urlarray[0]=$_REQUEST['url'];
 
 
	$arrLinks=getUrl($_REQUEST['keyword']);
 
	for($i=0,$j=1;$i<count($arrLinks);$i++,$j++){
		$urlarray[$j]=$arrLinks[$i];
	}
 
 
?>
 
<table border=1 width="80%">
	<tr>
		<th>Link</th>
		<th>Item #1</th>
  </tr>
<?php for($i=0;$i<count($urlarray);$i++){
// wait for 5 seconds = 5,000,000  HUMAN EMULATION
//usleep(5000000); 
 
//Have a bit of a rest before we go check the next keyword  3-6 seconds
sleep(rand(2,3));
?>
	<tr>
		<td>
			<?php
			if($i==0){
			?>
				<a href="<?php echo $urlarray[$i];?>" style="color:blue"><?php echo $urlarray[$i];?></a>
			<?php
			}
			else{
			?>
				<a href="<?php echo $urlarray[$i];?>"><?php echo $urlarray[$i];?></a>
			<?php
			}
			?>        </td>
	<?php
	
	  
	  # Google Cache Code....
	//echo $urlarray[$i]; 
	  //$url=urlencode($url); 
#echo "$url";
    $data=file_get_contents("http://www.google.com/search?hl=en&as_q=cache:".$urlarray[$i]."&as_occt=cache"); 
	//echo "Url is: $data";     
    //strip off HTML 
    $data=strip_tags($data); 
	//echo "$data";
    //now $data only has text NO HTML 
#echo "$data";
    //these have to found out in the fetched data 
    $find='as it appeared on '; 
    $find2='. The'; 
	//$find='of about '; 
    //$find2=' for'; 
 
    //have text beginning from $find 
    $data=strstr($data,$find); 
#echo "$data";
    //find position of $find2 
    //there might be many occurence 
    //but it'd give position of the first one,  
    //which is what we want, anyway 
    $pos=strpos($data,$find2); 
#echo "$pos";
    //take substring out, which'd be the number we want 
    $search_number=substr($data,strlen($find), $pos-strlen($find)); 
	//echo "$search_number";
	  
	
	?> 
 				<td>I would like result to print here</td>
	</tr>
 
<?php } ?>
</table>
 
</fieldset>
<?php
}
else if(isset($_REQUEST['Submit']))
{
	echo 'Please Enter a URL.';
}
?>
	</body>
<!--<?php include('includes/footer.php'); ?>-->
</html>
 
 
<!--Second Script-->
 
<?php
ob_start();
 
//put your site's URL here, but leave off the http://www
$url = "windmillaeration.com";
 
//put all the keywords you want to check here, make sure you leave the single quotes and commas intact for each keyword
$keywords = array(
'"pond aeration"',
//'windmill aeration',
//'windmill',
);
 
//Just tells us what URL we're checking rankings for
echo "<h2> Google SERPS For " .$url. "</h2>";
 
//start to run through each of the keywords
foreach($keywords as $keyword)  {
 
//set our counter at zero, so we can work out what the ranking of the page
$count = 0;
 
//make a URL that we can query Google with
$search = "http://www.google.com/search?q=".urlencode($keyword). "&num=100";
//now go get that page
$google = file_get_contents($search);
 
//funky regular expression stuff to find our URL in the results
$description= ('/<h3 class=r><a href=\"(.+?)\" class=l/');
preg_match_all($description,$google,$match);
 
//start looping through each of the results on the page
foreach( $match[1] as $value){
$count = $count + 1;
 
//check each of the 100 results from google, to see if our URL is in it.
if(strstr($value, $url)) {
 
//if this particular result has our URL in it, print it to the page, along with the ranking ($count variable from above)
echo $keyword. " - " .$count. "<br>";
ob_flush();
flush();
}
}
//Have a bit of a rest before we go check the next keyword, so we don't get booted from the Goog'
sleep(rand(30,60));
}
 
?>
 
Related Solutions
Keywords: PHP looping through urls and displaying…
 
Loading Advertisement...
 
[+][-]01/18/09 06:22 AM, ID: 23404974Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP Scripting Language
Sign Up Now!
Solution Provided By: Ray_Paseur
Participating Experts: 1
Solution Grade: B
 
[+][-]01/17/09 03:21 PM, ID: 23402951Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/17/09 03:32 PM, ID: 23402986Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/17/09 11:57 PM, ID: 23404134Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/17/09 11:58 PM, ID: 23404136Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/18/09 06:10 AM, ID: 23404936Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/18/09 06:13 AM, ID: 23404944Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/18/09 06:19 AM, ID: 23404963Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/18/09 08:19 AM, ID: 23405339Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625