PDA

View Full Version : PHP site to text



kumoshk
September 26th, 2009, 04:55 AM
In PHP, how do I pull the text from some online website that is not mine (through inputting a URL into a function) and store that text in a variable?

I need to get some information from a limitless number of similarly formatted pages online.

-grubby
September 26th, 2009, 06:22 AM
Shortcut:



$contents = file_get_contents("http://google.com");

kumoshk
September 26th, 2009, 06:52 AM
Shortcut:



$contents = file_get_contents("http://google.com");


Awesome. Thanks!

kumoshk
September 26th, 2009, 07:10 AM
Shortcut:



$contents = file_get_contents("http://google.com");


Huh. This actually didn't do what I wanted after all. I mean, all I see is a bunch of css and JavaScript. A lot of the actual text is missing. How do I get rid of everything but the text displayed after the HTML is rendered?

-grubby
September 26th, 2009, 07:16 AM
Huh. This actually didn't do what I wanted after all. I mean, all I see is a bunch of css and JavaScript. A lot of the actual text is missing. How do I get rid of everything but the text displayed after the HTML is rendered?

That just gets the source for the page. It isn't a browser engine, sorry

wojox
September 26th, 2009, 07:20 AM
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);

$contents = file_get_contents("http://google.com");

$currentstring1=get_string_between($currentstring,"1","2");
Replace 1 with the first beginning of the file and 2 with the end of the file.
In other words find your main contents begining and ending.

credobyte
September 26th, 2009, 12:14 PM
If it would be possible, we wouldn't need XML.