Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 06-18-2006, 10:16 AM   #1
4Pics
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Posts: 7,952
PHP Help ...

How do I grab a certain word from a webpage?

For example

PHP Code:
$handle fopen("http://www.blah.com""rb");
$contents '';
while (!
feof($handle)) {
  
$contents .= fread($handle8192);
}
fclose($handle); 
That will assign the text to $contents, but then how do i find the text I want?

I know its seperated uniquely on the page by a <span class="blah">textiwant</span>

Please help

Thanks
4Pics is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:18 AM   #2
nestle
Confirmed User
 
Industry Role:
Join Date: Apr 2006
Posts: 647
Best to use regular expressions with the preg_match function:
http://us2.php.net/manual/en/function.preg-match.php
nestle is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:20 AM   #3
psili
Confirmed User
 
Join Date: Apr 2003
Location: Loveland, CO
Posts: 5,526
lookup the function

preg_match()


and write a regular expression to grab your contents. Something like:

$reg="/<.*>?(.*)<.*>/" or something like that.

I haven't tried opening a url with "file_get_contents()" but you could try that instead of your loop, also.
__________________
Your post count means nothing.
psili is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:23 AM   #4
Dirty D
Confirmed User
 
Dirty D's Avatar
 
Join Date: May 2002
Location: Paying Webmasters Millions Since 1999
Posts: 4,044
This is what you want:

$contents = str_replace("textiwant", "replacementtext", $contents);
Dirty D is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:25 AM   #5
pussyluver
Clueless OleMan
 
Join Date: Mar 2003
Location: ICQ - 169903487
Posts: 11,009
Quote:
Originally Posted by 4Pics
How do I grab a certain word from a webpage?

For example

PHP Code:
$handle fopen("http://www.blah.com""rb");
$contents '';
while (!
feof($handle)) {
  
$contents .= fread($handle8192);
}
fclose($handle); 
That will assign the text to $contents, but then how do i find the text I want?

I know its seperated uniquely on the page by a <span class="blah">textiwant</span>

Please help

Thanks
WEB Police want to know what you are going to use this for???
pussyluver is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:28 AM   #6
4Pics
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Posts: 7,952
Quote:
Originally Posted by pussyluver
WEB Police want to know what you are going to use this for???
I want to grab scores from games and team names.
4Pics is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:29 AM   #7
testpie
Mostly retired
 
testpie's Avatar
 
Industry Role:
Join Date: Apr 2006
Location: UK
Posts: 3,231
If you are hosting with DreamHost (who disallow file(), file_get_contents() and similar using URL wrappers - so you have to use CURL), use:
PHP Code:
# Begin CURLing
  
$ch curl_init();
  
curl_setopt($chCURLOPT_URL"http://www.blah.com");
  
# Get content
  
curl_setopt($chCURLOPT_RETURNTRANSFER1);
  
$content curl_exec($ch);

  
# Get word from regex string
  
preg_match("'<span class=\"blah\">(.*?)</span>'i"$content$word); 
Otherwise (nearly all other webhosts) use:
PHP Code:
# Get content and load into string
 
$content file_get_contents("http://www.blah.com");

  
# Get word from regex string
  
preg_match("'<span class=\"blah\">(.*?)</span>'i"$content$word); 
In both instances the word you are looking for is returned in the variable $word.

Hit me up on ICQ if you have any problems.
__________________

Affiliates: DogFart ~ Domain parking: NameDrive ~ Traffic broker: Traffic Holder
testpie is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:29 AM   #8
nestle
Confirmed User
 
Industry Role:
Join Date: Apr 2006
Posts: 647
Quote:
Originally Posted by dustman
This is what you want:

$contents = str_replace("textiwant", "replacementtext", $contents);
I think you misunderstood. He does not know what 'textiwant' is nor does he want to replace it. He wants to find what 'textiwant' is.
nestle is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:32 AM   #9
4Pics
Confirmed User
 
Industry Role:
Join Date: Dec 2001
Posts: 7,952
Quote:
Originally Posted by testpie
If you are hosting with DreamHost (who disallow file(), file_get_contents() and similar using URL wrappers - so you have to use CURL), use:
PHP Code:
# Begin CURLing
  
$ch curl_init();
  
curl_setopt($chCURLOPT_URL"http://www.blah.com");
  
# Get content
  
curl_setopt($chCURLOPT_RETURNTRANSFER1);
  
$content curl_exec($ch);

  
# Get word from regex string
  
preg_match("'<span class=\"blah\">(.*?)</span>'i"$content$word); 
Otherwise (nearly all other webhosts) use:
PHP Code:
# Get content and load into string
 
$content file_get_contents("http://www.blah.com");

  
# Get word from regex string
  
preg_match("'<span class=\"blah\">(.*?)</span>'i"$content$word); 
In both instances the word you are looking for is returned in the variable $word.

Hit me up on ICQ if you have any problems.

Thanks, this worked .. Now I just have to play around to get the rest of it.
4Pics is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:33 AM   #10
2HousePlague
CURATOR
 
Join Date: Jul 2004
Location: the attic
Posts: 14,572
Quote:
Originally Posted by 4Pics
I want to grab scores from games and team names.



2hp
__________________
tada!
2HousePlague is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:35 AM   #11
gooddomains
Too lazy to set a custom title
 
Join Date: Jul 2003
Location: Netherlands
Posts: 10,127
some nice info
gooddomains is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-18-2006, 10:48 AM   #12
testpie
Mostly retired
 
testpie's Avatar
 
Industry Role:
Join Date: Apr 2006
Location: UK
Posts: 3,231
Quote:
Originally Posted by 4Pics
Thanks, this worked .. Now I just have to play around to get the rest of it.
Glad to have helped - now if you could just forward the hookers and booze to...
__________________

Affiliates: DogFart ~ Domain parking: NameDrive ~ Traffic broker: Traffic Holder
testpie is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.