View Single Post
Old 01-11-2010, 04:54 PM   #8 (permalink)
russellharrower
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default

@Cypher I think you hit it on the head, Just testing it and adding a few things...

However did not go to plan here is the code.
Code:
<?php

$config['url']       = "http://swellnet.com.au/loc_report.php?region_id=27&state_id=3"; // url of html to grab
$config['start_tag'] = '5 Day Swell Graph </td>'; // where you want to start grabbing
$config['end_tag']   = '</body>'; // where you want to stop grabbing
$config['show_tags'] = 0; // do you want the tags to be shown when you show the html? 1 = yes, 0 = no

class grabber
{
	var $error = '';
	var $html  = '';
	
	function grabhtml( $url, $start, $end )
	{
		$file = file_get_contents( $url );
		
		if( $file )
		{
			if( preg_match_all( "#$start(.*?)$end#s", $file, $match ) )
			{				
				$this->html = $match;
			}
			else
			{
				$this->error = "Tags cannot be found.";
			}
		}
		else
		{
			$this->error = "Site cannot be found!";
		}
	}
	
	function strip( $html, $show, $start, $end )
	{
		if( !$show )
		{
			$html = str_replace( $start, "", $html );
			$html = str_replace( $end, "", $html );
			
			return $html;
		}
		else
		{
			return $html;
		}
	}
}

$grab = new grabber;
$grab->grabhtml( $config['url'], $config['start_tag'], $config['end_tag'] );

echo $grab->error;
$i = 0;
foreach( $grab->html[0] as $html )
{
	$s[$i++] = htmlspecialchars( $grab->strip( $html, $config['show_tags'], $config['start_tag'], $config['end_tag'] ) );
}

$s = $s[0];

print $s;
preg_match('/\WIDTH=\"300\" HEIGHT=\"300\"> <PARAM NAME=movie VALUE=\"(.*?)\"/sim', $s, $matches); 

$url = parse_url($matches[1]); 
parse_str($url['query'], $params); 

var_dump($params); 

?>
As you can see it prints the code $s but then does not do the next step.
russellharrower is offline  
Reply With Quote