In the previous post I showed you how to obtain Google Search Results using PHP. I went ahead and collaborated upon that previous tutorial and created a tool where users can enter in a specific URL and a string of keywords. When the user clicks submit, the page processes the request and let's the user know what result place that website is in for those keywords. You can check out the demo at: MyPlaceInLine.com. In this post I'm going to show you how I used the Google Search API to perform this exact functionality. I am also providing a download link where you can download the full source of this project.

As you can see the project is very simple and straight forward. The only downfall with using the Google Search API is that you are limited to 64 search results; therefore, if your website lives further than 64 results deep we will not be able to show which place it is in. If you have found this to be different or have found a work-around please post a comment about this.

Okay, the main functionality of this application lies in the results.php file where we take in two variables which are the Website URL and the Keywords the user enters. The full code is shown below:

responseData->results[$x-$old_x]->unescapedUrl, $_POST['url']) !== false) 
			{
				$found = true;
			}
		}
		
	}
	
	if($found)
	{
		$foundon = $x.'th';
		if($x == 1){ $foundon = $x.'st'; }
		else if($x == 2){ $foundon = $x.'nd'; }
		else if($x == 3){ $foundon = $x.'rd'; }
		
		echo $_POST['url'].' is located as the '.$foundon.' result when a user searches for "'.stripslashes($_POST['keywords']).'"';
	}
	else
	{
		echo "Sorry, it looks like you are in the nosebleed section. In order for someone to find that website for that keyword they will need to search through over 5 pages; and unfortunately, the average user only looks at the first few search results...";
	}
}
	
?>

Using the PHP code above you can easily see how to perform this functionality by taking in a JSON array and parsing it to see if we have correctly found the website for that keyword. Once we have found the keyword we exit the loop and print out the results to the user. Click here to download the source for this project.

If you have made any modifications you wish to share or if you have any questions make sure to leave a comment ;)


Login

or Sign Up

Sign Up

or Login
×
Want to create your own SAAS?

I can teach you to create your own Software as a Service. Click here to learn more!

Visit SAAS Adventure!