473,788 Members | 2,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.i n/search?hl=en&q= php&btnG=Google +Search&meta=",
"r");

while(!feof($fh ))

{

$output = htmlspecialchar s(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 1686
On Tue, 3 Jul 2007 13:24:23 +0530, "sathyashra yan"
<sa***********@ REMOVEggmmaaiil l.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.ph p" ... >
<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.i n/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_conten ts() 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*********@NO SPAMlibero.itwr ote in message
news:2v******** *************** *********@4ax.c om...
On Tue, 3 Jul 2007 13:24:23 +0530, "sathyashra yan"
<sa***********@ REMOVEggmmaaiil l.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.ph p" ... >
<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.i n/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_conten ts() 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*********@NO SPAMlibero.itwr ote in message
news:2v******** *************** *********@4ax.c om...
>On Tue, 3 Jul 2007 13:24:23 +0530, "sathyashra yan"
<sa*********** @REMOVEggmmaaii ll.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.ph p" ... >
<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.i n/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_conte nts() 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*******@attgl obal.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
4156
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 developed with PHP, you are not supposed to doubt that. As a proof that PHP pages could be crawled and indexed, refer this Google search
11
4234
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 make the design looks a bit rediculous. He also said that the big text cannot be hidden. I am just trying to find a compromise. Here are the questions: (1) Is it true that a page with an <H1> tag and very big font size will make a search...
5
3003
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 (a wicked phrase). Some but not all of the words of that phrase exist in my website. I reported it and they removed the link but did not give explanations.
2
11846
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 engines. A subject directory classifies websites into some category. Could anyone point me towards the differences between these three that are significant for an ebusiness web site owner?
3
4561
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. So I coded my little search engine, uploaded it and it didn't work with my host (Dreamhost.com): Warning: fopen(): URL file-access is disabled in the server
4
1886
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 copy the URL to his own web page, that I might be penalized because my page would include that text on the resulting page. For example, let's say that "GOD LOVES JOKES" has negative connotations. Someone could create:
5
2069
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 them to be indexed and built the catalog as per KB article, but I've run into an interesting problem. When you publish a website from Whidbey, it precompiles everything and strips out the searchable details of the page (metadata, html, etc)...
4
1353
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
2183
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 site) and I want to help my client get the best search engine listing. Because this is my first for-profit site, I'm not sure what I need to do for optimal search engine placement. I've been poking around the Web, and I think I have a good start,...
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.