We have decided to make use of the Google search engine to search our website and have been looking at a few differant ways of doing it, the first would be the Google API and PHP/SOAP however I have too many projects on my hand to setup/test PEAR/SOAP + the API and would like to impliment something simple.
I decided it would be best to mimic the search on php.net and thought it would be simple enough to make a form and have it submit to a redirect that forms the search into a Google search url (Search+String+Site:mysite.com).
I've built my script and it will search correctly if I only input a single keyword; however spaces (" ") need to become pluses ("+") otherwise Google doesnt know what to do with multiple keywords.
All I really want is exactly what they have done on php.net, to take my entered words, seperate them by spaces and add the site:mysite.com option so it will use Google's index for items that are only part of my site. Does anyone have any reccomendations for how to finish this? Better yet has anyone ever done this before and would be willing to share their code?
Any help appreciated!
-Erik
Google search of website using php form
Moderator: General Moderators
-
spyordie007
- Forum Newbie
- Posts: 4
- Joined: Mon Oct 27, 2003 6:17 pm
- Location: Portland, OR; USA
From the source... Might be interesting.
http://cvs.php.net/co.php/phpweb/search.php
http://cvs.php.net/co.php/phpweb/search.php
-
spyordie007
- Forum Newbie
- Posts: 4
- Joined: Mon Oct 27, 2003 6:17 pm
- Location: Portland, OR; USA
I'm sorry, I've been looking at the code from the PHP site (thanks for linking me to that JAM) but havent had any luck understanding what part of the code is responsible for this. I'm not very good at PHP and wonder if anyone here would be kind enough to spell it out for me (i.e. look at line x, copy code make your form input variable x, etc.).
Thanks again
-Erik
Thanks again
-Erik
Okay 
Former page, line 45.
They are using urlencode() to change a forms input field's non-alphanumeric characters to %XX (xx being numerical hex equilant). Space is for example %20.
Line 81, same page
They are adding that variable in the search condition. You can clearly see what the different parts of the above url means, and what the different variables in it might do. q: query/question, site: where, l: language.
Now go experiment, and change this aroundto a combination that would work for you.
Former page, line 45.
Code: Select all
$ucp = urlencode($_FORM['pattern']);Line 81, same page
Code: Select all
"http://www.google.com/search?q={$ucp}+site:www.php.net&l=$LANG"Now go experiment, and change this aroundto a combination that would work for you.
-
spyordie007
- Forum Newbie
- Posts: 4
- Joined: Mon Oct 27, 2003 6:17 pm
- Location: Portland, OR; USA