zwkle Posted December 6, 2006 Share Posted December 6, 2006 Hi,I have a very simple requirement. I want to be able to use the php script below which was posted on another forum and which should tell me the number of google results for each member of a set of words in a text file. I'm completely new to php. What's the quickest way of running the script? After a couple of hours of research I tried pasting the code into notepad, saving it as a .php file, and uploading it to a free geocities hosting account. I couldn't view it in IE though--I just got a blank page. Am I on the right track? I just want to be able to use it in the simplest way possible.Andy <?php $file = file('path/to/your/list/of/words/to/search/for.txt'); $results = ''; foreach ($file as $line) { $data = file_get_contents("http://www.google.com/search?hl=en&q=" . urlencode($line) . "&btnG=Google+Search"); preg_match('/of about <b>([0-9,]*)?<\/b>/si', $data, $number); $results .= $line . " " . $number[1] . "\n"; } echo $results; ?> Quote Link to comment Share on other sites More sharing options...
Alchemy Posted December 6, 2006 Share Posted December 6, 2006 Well, first of all, it's blank right now because there's nothing it's searching for.you need to change path/to/your/list/of/words/to/search/for.txtfrom the line:$file = file('path/to/your/list/of/words/to/search/for.txt'); to the physical path to your .txt file that has your words you need to search for. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 6, 2006 Share Posted December 6, 2006 does Geocities support PHP? It needs to be supported in order to work.If the answer is no...check these out: http://www.free-webhosts.com/free-php-webhosting.php Quote Link to comment Share on other sites More sharing options...
zwkle Posted December 6, 2006 Author Share Posted December 6, 2006 hi alchemy -- thanks. That was an incredibly quick reply.I should have said that the file I uploaded to geocities was this one:<html><head> <title>PHP Test</title></head><body><?php echo '<p>Hello World</p>'; ?> </body></html> which is from the php manual. I saved this as a .php file before uploading it, but I'm not able to view it.Is this something to do with php not being enabled on geocities? (I uploaded this simpler php file just as a test) Quote Link to comment Share on other sites More sharing options...
trq Posted December 6, 2006 Share Posted December 6, 2006 What exactly do you see when you try and view it? More than likely Geocities does not support php by default but Im not sure. Quote Link to comment Share on other sites More sharing options...
zwkle Posted December 6, 2006 Author Share Posted December 6, 2006 I've never had so many replies on a forum in such a short space of time!Here is the url: http://www.geocities.com/avatar11235index.php is the hello world file above.At my end if i try to view it i get nothing but a blank page.I'm going to try a different host. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 6, 2006 Share Posted December 6, 2006 I would get a different host. all of these support PHP.PHP isn't supported on geocities free accounts.http://www.free-webhosts.com/free-php-webhosting.php Quote Link to comment Share on other sites More sharing options...
zwkle Posted December 7, 2006 Author Share Posted December 7, 2006 Ok, well I got a different host, phpnet.us, which does support php (as the name suggests) and I was able to upload the php test file and get it working.I then replaced it with this file:<html><head> <title>PHP Test</title></head><body><?php $file = file('http://www.geocities.com/avatar11235/cars.txt'); $results = '';foreach ($file as $line) { $data = file_get_contents("http://www.google.com/search?hl=en&q=" . urlencode($line) . "&btnG=Google+Search"); preg_match('/of about <b>([0-9,]*)?<\/b>/si', $data, $number); $results .= $line . " " . $number[1] . "\n"; } echo $results; ?> </body></html> (cars.txt has three words in it on separate lines -- I uploaded it onto geocities because I couldn't work out the correct path if I uploaded it onto phpnet.us)Now I get a blank page when I try to view the page. Does the code look right to you? It's meant to tell me how many google results there are for each entry in cars.txt. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 7, 2006 Share Posted December 7, 2006 The <?php and >? should go at the beginning and end (respectfully) of the script always. Before the HTML etc, so that the server knows that it needs to process PHP. You will probably have to echo out the HTML though.Whether that is the route cause of your problem is something else. Give it a try. Quote Link to comment Share on other sites More sharing options...
trq Posted December 7, 2006 Share Posted December 7, 2006 [quote]The <?php and >? should go at the beginning and end (respectfully) of the script always.[/quote]What? You can go in and out of php whenever and wherever you like. Quote Link to comment Share on other sites More sharing options...
zwkle Posted December 7, 2006 Author Share Posted December 7, 2006 If the problem isn't the <?php and >?, can you see any other problems? Quote Link to comment Share on other sites More sharing options...
Alchemy Posted December 7, 2006 Share Posted December 7, 2006 $file = file('http://www.geocities.com/avatar11235/cars.txt'); needs to be the PHYSICAL addresslike....users/psa/vhosts/freehosting.com/httpdocsor something... you have to find the physical address by asking your host. Quote Link to comment Share on other sites More sharing options...
trq Posted December 7, 2006 Share Posted December 7, 2006 [quote]needs to be the PHYSICAL address[/quote]The file() function can except a url just fine. I really can't see anything wrong witht this code, though Im no regx expert.Have you got error reporting enabled? That may give us a clue. Quote Link to comment Share on other sites More sharing options...
zwkle Posted December 7, 2006 Author Share Posted December 7, 2006 Ok,now I'm really confused. I changed the line $file = file('http://www.geocities.com/avatar11235/cars.txt'); to$file = file('cars.txt'); and put the cars.txt file in the same directory as the php file which I have named index.php.Now instead of a blank page I just get the three words in the text fill appearing all on one line.If anyone's really keen to help me with this I can let you know the control panel username and password. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.