Get string from other website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tonchily
Forum Commoner
Posts: 54
Joined: Thu Sep 02, 2010 10:44 am

Get string from other website

Post by tonchily »

I'd like to know if it's possible to make strings generated on other websites appear on mine website as a string, I mean I'd echo 'em.

For example:

http://www.footstar.org/ver_jogador.asp?jog_id=44797
I'd like to have dribbling skill and number to appear on my website as "Dribbling: 20"

is it possible? If yes, I would really appreciate if you could post the full code. Thanks in advance.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Get string from other website

Post by Jonah Bron »

Unless they have an API, you'd have to do something called scraping. Scraping requires you to get the contents of that page with cURL or file_get_contents() (the latter is easier), and grab the part you want with the DOM or Regex (again, the latter is probably better overall).

The only problem is, they might not like the load it puts on their site. You should get permission first. And if the say yes, you should cache it out of common courtesy.
tonchily
Forum Commoner
Posts: 54
Joined: Thu Sep 02, 2010 10:44 am

Re: Get string from other website

Post by tonchily »

Jonah Bron wrote:Unless they have an API, you'd have to do something called scraping. Scraping requires you to get the contents of that page with cURL or file_get_contents() (the latter is easier), and grab the part you want with the DOM or Regex (again, the latter is probably better overall).

The only problem is, they might not like the load it puts on their site. You should get permission first. And if the say yes, you should cache it out of common courtesy.
I've done the file_get_content(url) and echoed it out, and I do get the whole text (including that dribbling skill I want) but I don't know how to "crop" only that (guess that "cropping" method, if available, would be the easiest one)
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Get string from other website

Post by Jonah Bron »

On the page you gave, the html around the dribble skill is this:

Code: Select all

<div class="">Dribbling</div></td>            <td width="5%">&nbsp;</td><td align="right">&nbsp;</td><td align="center" width="5%"><div class="skill_text"><div class="skill_">20</div></div>
If you don't know how to write regular expressions (regex), you should learn:

http://www.regular-expressions.info/tutorial.html
viewtopic.php?f=38&t=33147
viewtopic.php?f=38&t=40169
tonchily
Forum Commoner
Posts: 54
Joined: Thu Sep 02, 2010 10:44 am

Re: Get string from other website

Post by tonchily »

Jonah Bron wrote:On the page you gave, the html around the dribble skill is this:

Code: Select all

<div class="">Dribbling</div></td>            <td width="5%">&nbsp;</td><td align="right">&nbsp;</td><td align="center" width="5%"><div class="skill_text"><div class="skill_">20</div></div>
If you don't know how to write regular expressions (regex), you should learn:

http://www.regular-expressions.info/tutorial.html
viewtopic.php?f=38&t=33147
viewtopic.php?f=38&t=40169
I've read all that ages ago but I don't know how to define and get that number (because on other players profiles not all have dribbling 20 etc). I know on how to "get" the dribbling string, but I fail at getting that number. Can you show me a specific example?

Thanks
Post Reply