was told to post here

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

was told to post here

Post by bla5e »

How do i get PHP to grab infomation/text from another website??

$data = file_get_contents ('http://caleague.com/?page=teams&teamid=42842');

Record <b>***this is what you want***</b><br/>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Please explain what data you're trying to extract? Please also bear in mind that it's illegal to take data from most websites in this way without prior consent from the author.

Regex can pull the data out using preg_match() but clearly we need an example of what data you want (the parts of the source code from the page in question) along with how you want it.

Read over some posts in this board if you're unsure how to show an example ;)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

its cal-league and its legal to take stuff from them if it is your own clan, many people do it. i told him to post this here and this:

Record <b>***this is what you want***</b><br/>

is the source code. its just whatever is inbetween those 2 bold tags is what he wants (where the ***this is what you want*** is at) but its gotta have the "Record" and the <br/> to find the exact bold tags to take stuff from you know?

But, yes, he should read over the tutorials first and try somtin himself. just trying to clarify it a bit
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

preg_match_all('@Record <b>(.*?)</b><br/>@is', $string, $matches);
print_r($matches);
:wink:
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

probably doing this wrong.. but heres what i did

Code: Select all

<?php      
    
$string = file_get_contents('http://www.caleague.com/?page=teams&teamid=42842'); 

    preg_match_all('@Record <b>(.*?)</b><br/>@is', $string, $matches); 
    print_r($matches); 
      
?>
and heres what happend:
Array ( [0] => Array ( [0] => Record 19-0-0
) [1] => Array ( [0] => 19-0-0 ) )
how do i get rid of the array text?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php      
    
$string = file_get_contents('http://www.caleague.com/?page=teams&teamid=42842'); 

    preg_match_all('@Record <b>(.*?)</b><br/>@is', $string, $matches); 
    echo $matches[1];
      
?>
8)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php      
    
$string = file_get_contents('http://www.caleague.com/?page=teams&teamid=42842'); 

    preg_match_all('@Record <b>(.*?)</b><br/>@is', $string, $matches); 
    echo $matches[1];
      
?>
8)
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

Jcart wrote:

Code: Select all

<?php      
    
$string = file_get_contents('http://www.caleague.com/?page=teams&teamid=42842'); 

    preg_match_all('@Record <b>(.*?)</b><br/>@is', $string, $matches); 
    echo $matches[1];
      
?>
8)
that just echos "Array" now
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Code: Select all

<?php      
    
$string = file_get_contents('http://www.caleague.com/?page=teams&teamid=42842'); 

    preg_match_all('@Record <b>(.*?)</b><br/>@is', $string, $matches); 
    echo $matches[1][0];
      
?>

...however, you should at least understand PHP *a little* and ask for help instead of showing up out of nowhere and asking for code. :?

Also, this topic is one month old. Not interested in your own problem? :|
Post Reply