rendered paste body<?php
set_time_limit(500);
## find everything before
function FindAllBefore($str, $delimit) {
if(strpos($str, $delimit) == false) { return false; }
else {
$pos1 = 0;
$pos2 = strpos($str, $delimit);
return substr($str, $pos1, $pos2);
}
}
## find everything before, including
function FindAllBeforeIncluding($str, $delimit) {
if(strpos($str, $delimit) == false) { return false; }
else {
$pos1 = 0;
$pos2 = strpos($str, $delimit)+strlen($delimit);
return substr($str, $pos1, $pos2);
}
}
## find everything after
function FindAllAfter($str, $delimit) {
if(strpos($str, $delimit) == false) { return false; }
else {
$pos1 = strpos($str, $delimit)+strlen($delimit);
$pos2 = strlen($str);
return substr($str, $pos1, $pos2);
}
}
## find everything after, including
function FindAllAfterIncluding($str, $delimit) {
if(strpos($str, $delimit) == false) { return false; }
else {
$pos1 = strpos($str, $delimit);
$pos2 = strlen($str);
return substr($str, $pos1, $pos2);
}
}
## find inside, including
function FindInsideIncluding($str, $start, $end) {
if(strpos($str, $start) == false) { return false; }
else if (strpos($str, $end) == false) { return false; }
else {
$pos1 = strpos($str, $start);
$pos2 = strpos(FindAllAfter($str, $start), $end)+strlen($end)+strlen($start);
return substr($str, $pos1, $pos2);
}
}
## find inside
function FindInside($str, $start, $end) {
if(strpos($str, $start) == false) { return false; }
else if (strpos($str, $end) == false) { return false; }
else {
$pos1 = strpos($str, $start)+strlen($start);
$pos2 = strpos(FindAllAfter($str, $start), $end);
return substr($str, $pos1, $pos2);
}
}
abstract class Parser {
protected $content;
protected $pageUrl;
public function __construct($url) {
$this->setUrl($url);
$this->content = $this->getPage();
}
public function setUrl( $url ) {
if(!empty($url)) {
$this->pageUrl = (string) $url;
}
}
public function getUrl() {
return $this->pageUrl;
}
private function getPage() {
return file_get_contents($this->pageUrl);
}
public function getContent() {
//echo $this->content;
return $this->content;
}
abstract function parse();
}
class YahooTravel extends Parser {
public function parse() {
}
}
$y = new YahooTravel('http://travel.yahoo.com/p-reviews-322437-prod-hotel-action-read-ratings_and_reviews-i;_ylt=AioDJMcIYnfZ0KDjF86t4gniphQB');
$html = $y->getContent();
$i = 0;
while( FindInsideIncluding($html, '<div class="usrrvw">', '</div>')) {
$reviews[] = FindInsideIncluding($html, '<div class="me">', '</div>');
$i++;
$html = str_replace($str, '', $html);
if($i == 10) {
break;
}
}
print_r($reviews);
?>
// returns
Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => )