PHP - Google Results Reading
I am trying to work out how to work out rank on google results.
I so far have the results of the first page however can not work out how to get to the next page. <?php function google_search_api($args, $referer = 'google.php', $endpoint = 'web'){ $url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint; if ( !array_key_exists('v', $args) ) $args['v'] = '1.0'; $url .= '?'.http_build_query($args, '', '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // note that the referer *must* be set curl_setopt($ch, CURLOPT_REFERER, $referer); $body = curl_exec($ch); curl_close($ch); //decode and return the response return json_decode($body); } $rez = google_search_api(array( 'q' => 'test', )); print_r($rez); ?> Now I working off the http://code.google.com/intl/en/apis/ajaxsearch/documentation/reference.html#_class_GSearch What I am trying to do is build is http://www.further.co.uk/tools/search-position-check/ I am almost there with doing it with bing results function bingrank($keyword,$domain){ $rank = '0'; $urls = array(); for($i=0;$i<10;$i++){ $rn=$i=='0'?'':$i; $query = "http://www.bing.co.uk/search?q=".urlencode($keyword)."&first=".$rn."1"; $result_page = file_get_contents($query); preg_match_all('/class="sb_tlst"><h3><a href="(.*?)"/',$result_page,$matches); foreach($matches[1] AS $url){ $urlst = str_replace('www.', "", preg_replace('(^http://|/$)','',$url)); $urlsz = explode("/", $urlst); $urls[] = $urlsz[0]; if ($urlsz[0] == $domain){ return $i+1; } } } return 'N/F'; } Any advice or help would be great. Similar TutorialsHello friends, Posting this thread after many months. Well I am making a small script in which on first page there will be a text box with button. What I want to have is, When we enter any keyword, like "yahoo" in textbox and click on submit button, on next page, there should be top 10 domain names from google search. One of the most important is it should have option to select pages from specific countries like from google.co.uk or google.com or google.jp, this should be on first page. I dont know how to fetch first 10 results domain names / URL and insert it in PHP variable and populate in table. Need help I am using html5 and all the pages have h2 headings as titles. They all show up in google search results fine. The only thing that doesn't show up fine are some of the descriptions under each heading. Some meta descriptions show up fine under the correct heading title, while rest shows ALL the heading tags AS description under each search result.
For eg.
Cars
www.mywebsite.com/category?id=5&name=cars Ok, so I have a bit of code but it's not working as it should, would one of you guys have a look at it and let me know where I'm going wrong? Basically I need to be able to input several words or terms into the text area, each on a separate line and have the results displayed something like: hello: 23,000.000 hello world: 19,000,000 world: 278,000,000 I also see that the script is not searching the words / terms inside quotes (EG. "hello world") TIA Code: [Select] <html> <body> <?php function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)') { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/'); $result = curl_exec ($ch); curl_close ($ch); return $result; } $s = $_GET['s']; if (isset($s)) { echo "<p><i>Search for $s</i></p>"; $s = urlencode($s); $data = my_fetch("http://www.google.com/search?hl=en&q=" . $s . "&btnG=Google+Search"); $data = strip_tags($data); $find = 'Results 1 - 10 of about '; $find2 = ' for'; $data = strstr($data, $find); $pos = strpos($data, $find2); $search_number=substr($data,strlen($find), $pos-strlen($find)); echo "Total Results: $search_number"; } else { ?> <form name="form1" id="form1" method="get" action=""> <div align="left"> <p> <textarea name="s" type="text" id="s" rows="8" style="width:60%" /></textarea><br /> <input type="submit" name="Submit" value="Results" /></p> Put "" around the string: <input type="checkbox" checked name="apos" value="true" /><br /> </div> </form> <p> <?php } ?> </p> </body> </html> I just can't wrap my head around it, but I am trying to integrate weather into my website using NOAA. 1. Here is the NOAA page: http://forecast.weather.gov/MapClick.php?CityName=Mio&state=MI&site=APX&lat=44.663&lon=-84.1446 2. Here is the XML to that page: http://forecast.weather.gov/MapClick.php?lat=44.66300&lon=-84.14460&FcstType=dwml Now what I want to do is to have PHP on my website that reads the XML from the NOAA site and create the "Forecast At A Glance". Possible or too challenging? [xml]<category id="SOCMENEURASTVICLEA" order="26800">Aus. Victoria League</category>[/xml] I have the above xml, I can read the category id, order but I dont no how to read the value "Aus. Victoria League" foreach($description->children() as $category) { foreach($category->attributes() as $a => $b) { echo "<br/> -------- "; echo $a,'="',$b,"\"\n"; } echo "category name" . $category->asXML(); } the asXML() i have no idea what that is but am guessing I need thats where the php function which returns the value needs to go Thank you PHP 5.3.8 XAMPP on Windows XP I have an XML file that manages the input to an mp3 player on this page http://www.jimslounge.com/segovia/ The structure looks like this Code: [Select] <content> <auto_play>yes</auto_play> <loop>yes</loop> <volume>60</volume> <artist> <song_title><![CDATA[Bach - Suite No. 3 - Allemande]]></song_title> <artist_name><![CDATA[Andre Segovia]]></artist_name> <image_path>load/images/segovia.jpg</image_path> <mp3_path>load/songs/Bach - Suite No. 3 (for solo cello, arr. Duarte)- Allemande.mp3</mp3_path> <url target="_blank" open="yes">http://en.wikipedia.org/wiki/Andr%C3%A9s_Segovia</url> </artist> <artist> ... with <artist> being the repeating element I want to be able to read and eventually write to If I run this Code: [Select] $xml = simplexml_load_file("load.xml"); var_dump($xml); I get this object(SimpleXMLElement)#1 (4) { ["auto_play"]=> string(3) "yes" ["loop"]=> string(3) "yes" ["volume"]=> string(2) "60" ["artist"]=> array(22) { => object(SimpleXMLElement)#2 (5) { ["song_title"]=> object(SimpleXMLElement)#24 (0) { } ["artist_name"]=> object(SimpleXMLElement)#25 (0) { } ["image_path"]=> string(23) "load/images/segovia.jpg" ["mp3_path"]=> string(74) "load/songs/Bach - Suite No. 3 (for solo cello, arr. Duarte)- Allemande.mp3" ... [/color] which is overwhelming This cleans it up but doesn't give me the artist name and song name I'm looking for. Code: [Select] $xml = simplexml_load_file("load.xml"); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; } The Output: content auto_play: yes loop: yes volume: 60 artist: artist: artist: My experience with simplexml only goes back a couple of hours so I'm pretty inept at this point. Any help will be greatly appreciated. Hello, I'm trying to read some XML by name this is the XML: Code: [Select] <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <imgdir name="01040000.img"> <imgdir name="info"> <canvas name="icon" width="29" height="30" basedata="iVBORw0KGgoAAAANSUhEUgAAAB0AAAAeCAYAAADQBxWhAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAMuSURBVEhLlZcBlatADEWxUAu1gAUs1AIWsIAFLGChFmphLXwL83ND3jQwlO5yTg6FmcnNSzLDbtf97io27Zv9ztOHWY3zZezKOHSl7/ud8Y6x1/IxoK+BOGwd+zIN99LfN4dnQGAVuG5zmD8Nt7I87u6D55SdU3jh2hZuwPK6lfJvKq9wmkH/nhtId+bPBvtZRgeOva219WQgZaEB++DjfqtQHArs9wjCnVkgCoZ1QIGhEuBgfvyyoJlPgKG6gn1AwKo0FjjcfisIqXOwAW83MysLqZ0MyD0r9Wy9a/6GKloBH7YYZx4plwUlqGBE70CZgVGaU4xifJ+pdZWkRw0AlGhx+JwDHmnNsN7GZahVioFLsac66ptTvKXFjNr0/bB1LvWxptqpCVUERaAC4hgo5kAbVxdL7THFNSUZiuPF1KvW+TdjlAKHgAVFicCoJtVqLvf93kZbWngxPMaqVGpwzsLcaAIKChgYUHxUxWquyCTzleK6TaZp9kUMKEJg7jwiBahtIZVZrXwo3Vp3VEobOyxDmQSw7rc4KDwjEUhOsdTiY56X6ktwZSKfED4Rk1Lvutir+XTxIy8aqnZudLHv14BmMM15PBxc6bI+a4SLPb/Mfsxstt95xhjDprCH3TGeee/1XNed2jOoR5ehcpDBGX4FPkJzyZrUCkp6z5RK7TelW9bWRm1z9qqeiupuCzF92vR505fm7MDQO5zj75jiBiqYmsj3KJ+naCR9VThVCEDj3POW4FlQ+fQT7qqRmMgiTpLnNOzA+qThmDHN4aSabe9iOnGkUh181rnevdlwxB4kZXIodfrQa85RtdQefF7+2eIKstJcP4BSmefxTor9UIk0f/0DKSb4YlSycPCvzvuPMaLXYc88zdV81fjP0FwrAcdxLJhvB4NltfzOSinHX6A7lR61qcxAg9reP1d7Udvv9VTU27e1gfaf1CrdufGimVhj294Dbq5ayw9AOx072a621FSW925AR7vb8dwBb8CeXprnuIXseTazE3BnzX7NezZ8EOQl1OsVRmRMxrLC4++r/2/wMYTCj+kl34CZICMlR5Oj4/u8ThD8NSn9D9wL1z9uxdBdAAAAAElFTkSuQmCC"> <vector name="origin" x="-2" y="30"/> </canvas> <canvas name="iconRaw" width="29" height="29" basedata="iVBORw0KGgoAAAANSUhEUgAAAB0AAAAdCAYAAABWk2cPAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAL4SURBVEhLlZYBtYMwDEVnAQuzgAUsYAELWMACFrAwC7MwC99Cf27o6wJ0sO2cHAZNc/PStHC7ffdL5nZl30X64HUIPg+3NHS31LbtxnjG2HP+mNBlIg5bhjaN3T219zVgDQisAJfVB/+xa9Lc3z0G96E6VXjit05cgenZpPQ3pmcOGkF/jxWkK/6TwV7z4MChtbk2nwqEKhzAPtjfmwIloMB+zUl4MEtEyTAPKDBUAuwsjv8safxJMKsuYB8QsCjNExxu/5WE1DnYgE1jZstCaUcDco1KvVrvNX9Dla2AvU0mmGfKz5ISVDCyd6DMwCiNJUYxsWtqXSXlUQMAJVsCPqYMz2WNsNbGZahViYFLsZc6r28s8VoWM9ambbu1c1kfa6qNmqyKpEhUQAIDxRxo4+piqd2XuJQkQgk8m3qtdfzPGEtBQMCCokRgVFNqNZfHfm+jtSw86PqhKJUagjMxNpqAggIGBpQYRbGaK1cSf5W4bJNxnHwSA8oQmAfPmQLUtpDKqFYxVG7N2yuljR0WoTgBLPstHxRekZxILLHUEmOa5hJLcFUinhDuiEmpd13eq/F08SMvN1Tp3NzFvl8zNIJpzv3h4Ern5VEynO3+afYyM2+/co8xho3Zerti3PPc13NZNmprUM8uQhUggiP8DLyHxiU7lFZQyltTKrVXSteqLQe1h7NX66ms7jYR06tNrze9aWoHhp4RnHj7Eh+ggqmJfI/yesqNpLcKpwoJaJxr3BLcC6qYfsKdNRKOTOIkeYzdBqxXGoEZkw8n1WR7F9OJI5Xq4FrnevdGIxB7kJIpoNTpRS+fvWqp3cU8/WxxBVFpXD+AUhn9eCbFfqjkMl9+IGUHn4xKJnb+1nl/jJG9Dnv85Ct/rfHP0LhWAg7DkDDfDgaLavkflbIcv0A3Kj1rUxmBqkZN7cnaXq+nsl7frXVoTa3KHRvvU9duTiatzQlQ/pu1ZZ4s7t2voGRL8+y30If6HPZr3LPfAIuCX5wryV1+1QP6B07yxunYFCcQAAAAAElFTkSuQmCC"> <vector name="origin" x="-2" y="30"/> </canvas> <string name="islot" value="Ma"/> <string name="vslot" value="Ma"/> <int name="reqJob" value="1"/> <int name="reqLevel" value="40"/> <int name="reqSTR" value="130"/> <int name="reqDEX" value="0"/> <int name="reqINT" value="0"/> <int name="reqLUK" value="0"/> <int name="incDEX" value="3"/> <int name="incMMP" value="10"/> <int name="incPDD" value="45"/> <int name="tuc" value="7"/> <int name="price" value="6700"/> <int name="cash" value="0"/> </imgdir> Say I want to get reqJob and print it onto the page. Also I would need to get the BaseData of the iconRaw canvas. The following script just validates some form inputs, and then puts any errors inside an array. I get this error: Fatal error: Cannot use [] for reading in C:\xampp\htdocs\Game\includes\validation.php on line 104 I've looked around, and this still does not make any sense to me. public function ValidateEmail($email, $reemail){ /* Sanatize. User filter_var to validate. Make sure both emails match. Check if email already exists or not. */ trim($email); strip_tags($email); mysql_real_escape_string($email); trim($reemail); strip_tags($reemail); mysql_real_escape_string($reemail); if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ $this->valid = false; //Line 104 $this->error[] - "The E-Mail that you provided is not valid."; } else { $this->valid = true; } if($email !== $reemail){ $this->valid = false; $this->error[] = "The E-Mail's that you provided do not match."; } else { $this->valid = true; } if(filter_var($email, FILTER_VALIDATE_EMAIL) && $email == $reemail){ $checkmail = mysql_query("SELECT users.email, temp_users.email FROM users, temp_users WHERE email = '$email'"); if(mysql_mum_rows($checkmail) == 1){ // email is found, throw out error $this->valid = false; $this->error[] = "That E-Mail is already in use."; } else { $this->valid = true; } } return $this->error; } Line 104 is commented out. Thanks! how can I read a url coming from another site by header('Location:') command I am trying to use this weeklyReport1Boles.html: Code: [Select] <html> <head> <title>Weekly Report</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <h1>Weekly Report</h1> <p> <form action = "weeklyReport1Boles.php" method = "post" > <p> <input type = "submit" value = "Display the Report" /> </p> </form> </body> </html> TO PULL data from weeklyDataBoles.txt lines 1-8 1 236.00 2 284.00 3 148.00 4 128.00 5 0.00 6 110.00 7 0.00 8 THE RESULTING WEB PAGE SHOULD BE: Weekly Report TOTAL INCOME FROM PAINT CONTRACTS: $0.00 AVG DAILY INCOME FROM PAINT CONTRACTS: $0.00 NUMBER OF DAYS with NO INCOME: . MY PHP CODE IS: <?php $total = $_POST['total']; $avgDailyIncome = $_POST['avgDailyIncome']; $badDays = $_POST ['badDays']; $paintFile = fopen("weeklyDataBoles.txt","r"); $year = fgets($weeklyDataBoles); $total = 0; for ($count= 1; $count <=7; $count = $count +1) { $nextDay = fgets($weeklyDataBoles); $total = $total + $nextDay; } fclose($weeklyData); $avgDailyIncome = $total/7; print("<p>TOTAL INCOME FROM PAINT CONTRACTS: "); print("$".number_format($total, 2)."</p>"); print("<p>AVG DAILY INCOME FROM PAINT CONTRACTS: "); print("$".number_format($avgDailyIncome, 2)."</p>"); print("<p>NUMBER OF DAYS with NO INCOME: $badDays.</p>"); ?> </body> </html> THE AVERAGES ARE BASED ON ONE WEEK OR SEVEN DAYS, WHY CANT I OPEN THE FILE AND GET THE PROGRAM TO READ IT, I AM A STUDENT AND VERY, VERY, VERY BAD AT THIS, MAKES ME CRAZY CAUSE I REALLY LOVE IT Hi People. Here is a form that is supposed to read from my database. My primary key is called "index" and I have about 300 records in the database. I wanted to be able to view the records but when I load this page the "php" part is empty. I simply get given a blank form. I know it is connecting to the DB OK because I changed one letter in the password and then got a "can't connect to the database error" just to test it out. Code: [Select] <?php $host = 'localhost'; $usr = "the_db_user"; $password = 'not_shared_on_forum'; $db_name = 'stranded'; function cr($string){ $clean_string = str_replace("rn","<BR>",$string); return $clean_string; } //$id = 11; if (!isset($id)) $id = $_GET['id']; mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); $read_query = "select * from HelperFormData where index = '$id'"; $results = mysql_query($read_query); $rs = mysql_fetch_array($results); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- body,td,th { font-size: 12px; } --> </style></head> <body> Surname: <? echo $rs["surname"]; ?> <table width="500" border="1" bordercolor = "#2c2cf6" textcolor = "#2c2cf6"cellspacing="1" cellpadding="2"> <tr> <td colspan="5">Record number: <? echo $rs["index"]; ?></td> </tr> <tr> <td width="120" bgcolor = #E6F8EB>Surname</td> <td width="120" bgcolor = #E6F8EB>First Name</td> <td width="120" bgcolor = #E6F8EB>phone1</td> <td width="120" bgcolor = #E6F8EB>phone2</td> <td width="120" bgcolor = #E6F8EB>Location</td> </tr> <tr> <td bgcolor = #E6F8EB textcolor = #AC1636><strong><? echo $rs["surname"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["firstname"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["phone1"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["phone2"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["location"]; ?></strong></td> </tr> <tr> <td bgcolor = #dbeff8>Qualifications</td> <td bgcolor = #dbeff8>Expertise</td> <td bgcolor = #dbeff8>Assistance</td> <td bgcolor = #dbeff8>Languages</td> <td bgcolor = #dbeff8>E-Mail</td> </tr> <tr> <td bgcolor = #dbeff8><strong><? echo $rs["qualifications"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["expertise"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["assistance"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["languages"]; ?></strong></td> <td bgcolor = #dbeff8><strong><? echo $rs["e_mail"]; ?></strong></td> </tr> <tr> <td bgcolor = #E6F8EB>Consent</td> <td bgcolor = #E6F8EB>Published</td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> </tr> <tr> <td bgcolor = #E6F8EB><strong><? echo $rs["consent"]; ?></strong></td> <td bgcolor = #E6F8EB><strong><? echo $rs["radio_callsign"]; ?></strong></td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> <td bgcolor = #E6F8EB> </td> </tr> <tr> <td colspan="5"><p>Comments:<br /> <strong><? echo $rs["comments"]; ?></strong></td> </tr> </table> </body> </html> </html> I've never been very good with arrays, and am totally new to them in PHP... If I have this array... Code: [Select] $concertDates = array('201105071'=>'May 7, 2011 (9:00am - 12:00pm)', '201105072'=>'May 7, 2011 (1:00pm - 4:00pm)', '201105141'=>'May 14, 2011 (9:00am - 12:00pm)'); ...and I know the key, e.g. Code: [Select] $concertDate = '201105072' Then how do I get the corresponding value, i.e. Code: [Select] May 7, 2011 (1:00pm - 4:00pm)' ...from the array?? Debbie I have been studying PHP for a long time. I can write a simple PHP guestbook now. But you know, it's so so so simply, even the green hand can attack on my site. I want to improve my PHP skill, so i decide to read a big php program such as a shopping cart. Finally i choose the cart Eclime. But when i read the code, i find it's so difficult for me to understand it. Maybe i am in the wrong way to study PHP. Anyone tell me what i should do now ... I am trying to go through all of the emails in an inbox with php. I saw a way to do it with imap_open, but I don't have the imap functions installed. Does anyone know of another way to do this? I would think someone would have written a 3rd party library that just uses sockets -- kind of like phpmailer but for receiving instead of sending. Hi there I am working on PHP form which has an array named: $productOptions. When I do: print_r($productOptions); it returns: Array ( [124] => Array ( [optionId] => 124 [optionName] => acer aspire [optionListId] => 28 [dateCreated] => 2010-11-04 12:48:53 [enabled] => 1 [optionQtyId] => 84 [productId] => 40 [quantity] =>7 ) [114] => Array ( [optionId] => 114 [optionName] => acer fast [optionListId] => 28 [dateCreated] => 2010-11-01 02:04:53 [enabled] => 1 [optionQtyId] => 83 [productId] => 40 [quantity] => 0 ) Now from this Array, I would like to check if the quantity if greater than Zero. so I tried: if (productOptions[quantity] > 0){ echo "blah blah..." } But for getting the quantity, the part: productOptions[quantity] returns nothing. Am I doing this correctly? Please reply. Thank you hi i am a making a site in which m saving a songs information in database then fetching that out for inserting song link m using readdir function that read all song in a folder then save them in database but i have problem when that read file name .mp3 also include with that which i don't want to show on page where i fetch that mean simply i want that i can insert song name separately and file separately... and i want to use readdir also for getting file name becoz that easy way instead of upload through panel ..? any idea or solution about adding separately file name Hi all, how do I read emails sent to an email account on my site such as admin@mysite.com? Code: [Select] $_POST['amount'] = intval($_POST['amount']); if ($_POST['amount'] < 0){ message($lang_common['Bad request']); } if (!is_numeric($_POST['amount'])){ message($lang_common['Bad request']); } echo $pun_user['gold']; echo '<br>'; echo $_POST['amount']; exit; if I enter 0.05 in my gold input textbox and submit it, it reads 0, it doesn't read the decimal values, i need it to read them, but I also need it to be secure and use intval.. help While testing... php seems to be changing the & symbol into a square bracket when retrieving from $_GET. I assume this is so it can still use the & to seperate variables placed into the URL. When i print_r the $_GET i get this: [name] => [lt;table] My question is... is there a function which decodes this? For example, the name, "<table>" is actually stored in my table due to html entities as you see therefore if the name is ever passed via the URL, the & messes it all up. Furthermore, are there any other characters like this i should be looking out for? |