473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

fopen() with url and search engine (beginner)

Dear group,

When I went through the php docs I come across with fopen() function
which can also takes the any url. So I tested with this following little
code.

<?php

$fh =
fopen("http://www.google.co.in/search?hl=en&q=php&btnG=Google+Search&meta=",
"r");

while(!feof($fh))

{

$output = htmlspecialchars(fgets($fh, 1024));

echo ("$output<br />");

}

fclose($fh);

?>

The query string does that all. If I want to have my own page with a text
box and a submit button which searches the google and display those google
search result links in my web page. Can that be possible? Is this the basic
thing about search engine? Or I am I missing something very basic? Thanks
for any help.
Jul 3 '07 #1
4 1670
On Tue, 3 Jul 2007 13:24:23 +0530, "sathyashrayan"
<sa***********@REMOVEggmmaaiill.comwrote:
If I want to have my own page with a text
box and a submit button which searches the google and display those google
search result links in my web page. Can that be possible?
You need to set the 'q' var in the query string you pass to google.com.

In your page.php:

....
<form action="page.php" ... >
<input name="str" type="text" />
<input type="submit" value="Search" />
</form>

<?php
if (isset($_POST['str'])) {

$str = $_POST['str'])
$fh = fopen('http://www.google.co.in/search?q=' . $str, 'r');
...
fclose($fh);

}
?>

However, if you have already sent any html (eg. that <form>) you should
not print out again the <html>, <head>, <body>, etc, html tags coming
from google.co.in. You should strip them out. Take a look at file() or
file_get_contents() or, better, see <http://www.google.com/apis/>.

Giovanni

--
Advanced PHP Programming? See <http://snipr.com/1nsyy>
Ajax in Practice? See <http://snipr.com/1nsyz>
"I bougth them on Amazon.com, I swear I'll sell them only once."
Jul 3 '07 #2

"Giovanni R." <le*********@NOSPAMlibero.itwrote in message
news:2v********************************@4ax.com...
On Tue, 3 Jul 2007 13:24:23 +0530, "sathyashrayan"
<sa***********@REMOVEggmmaaiill.comwrote:
>If I want to have my own page with a text
box and a submit button which searches the google and display those
google
search result links in my web page. Can that be possible?

You need to set the 'q' var in the query string you pass to google.com.

In your page.php:

...
<form action="page.php" ... >
<input name="str" type="text" />
<input type="submit" value="Search" />
</form>

<?php
if (isset($_POST['str'])) {

$str = $_POST['str'])
$fh = fopen('http://www.google.co.in/search?q=' . $str, 'r');
...
fclose($fh);

}
?>

However, if you have already sent any html (eg. that <form>) you should
not print out again the <html>, <head>, <body>, etc, html tags coming
from google.co.in. You should strip them out. Take a look at file() or
file_get_contents() or, better, see <http://www.google.com/apis/>.
Thanks a lot.. it a very useful information. So each search has it's own way
of query string. Is it? yahoo has it own.. altavista has it's own..
wont they change it in the future..?

Jul 3 '07 #3
sathyashrayan wrote:
"Giovanni R." <le*********@NOSPAMlibero.itwrote in message
news:2v********************************@4ax.com...
>On Tue, 3 Jul 2007 13:24:23 +0530, "sathyashrayan"
<sa***********@REMOVEggmmaaiill.comwrote:
>>If I want to have my own page with a text
box and a submit button which searches the google and display those
google
search result links in my web page. Can that be possible?
You need to set the 'q' var in the query string you pass to google.com.

In your page.php:

...
<form action="page.php" ... >
<input name="str" type="text" />
<input type="submit" value="Search" />
</form>

<?php
if (isset($_POST['str'])) {

$str = $_POST['str'])
$fh = fopen('http://www.google.co.in/search?q=' . $str, 'r');
...
fclose($fh);

}
?>

However, if you have already sent any html (eg. that <form>) you should
not print out again the <html>, <head>, <body>, etc, html tags coming
from google.co.in. You should strip them out. Take a look at file() or
file_get_contents() or, better, see <http://www.google.com/apis/>.

Thanks a lot.. it a very useful information. So each search has it's own way
of query string. Is it? yahoo has it own.. altavista has it's own..
wont they change it in the future..?
Why should they? It works fine for them.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 3 '07 #4
Thanks for all the help.. It helped me a lot..
Jul 3 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: R. Rajesh Jeba Anbiah | last post by:
Q: Is PHP search engine friendly? Q: Will search engine spiders crawl my PHP pages? A: Spiders should crawl anything provided they're accessible. Since, nowadays most of the websites are been...
11
by: Petre Huile | last post by:
I have designed a site for a client, but they have hired an internet marketing person to incrase their search engine ranking and traffic. He wants to put extra-large fonts on every page which will...
5
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine...
2
by: Patrick | last post by:
Are the differences between a search engine, a subject directory and a meta search engine significant for an ebusiness web site owner? A meta search engine merely uses ordinary existing search...
3
by: James | last post by:
Hi guys, I have been building a search engine here - not because I have plans of dethrowning Google but as a simple app upon which to develop a function set that I can use for other things. ...
4
by: John | last post by:
Greetings, all, Several days after adding personalized URLs to my "amazing" collection of "God Loves (yourname)" mazes, it occurred to me that if someone were to create an offcolor term, then...
5
by: Sam | last post by:
Does anyone know of a way to create a search page under ASP.NET 2.0? I have started out by configuring a catalog in Index Server, registering the aspx, ascx extensions in the registry to allow...
4
by: Shun | last post by:
Hello, May i Know about the SEO(Search Engine Optimization). can i have any code for the SEO. Thanx, regards Shun
4
by: MDW | last post by:
Posted this on another board, but evidently it was off-topic there...hope you folks will be able to provide some guidance. I've been working on a Web site for a business (my first non-personal...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.