Jump to content

Simple page scraping with PHP?


jim.dandy

Recommended Posts

<?php

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);

}

 

$data = file_get_contents('http://www.thepiratebay.org/top/201');

 

$data2 = explode("<td>",$data);

echo count($data2);

 

for($x=0;$x<count($data2);$x++){

 

echo get_string_between($data2[$x], "Y-day", ".torrent");

 

}

 

?>

 

 

 

I found a function someone made that grabs a string between two strings.  It kinda works but doesn't grab everything I want.  I dont understand why it won't work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.