<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: grabber code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 22:06:33 GMT</pubDate>
    <description>DZone Snippets: grabber code</description>
    <item>
      <title>Grab HTML From Sites and Echo Results</title>
      <link>http://snippets.dzone.com/posts/show/2245</link>
      <description>Grabs specified tags from any url on the net and then echos each of the results on a seperate line, you then have the option to remove the tags from the echoed results.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$config['url']       = "http://www.business-tycoon.com"; // url of html to grab&lt;br /&gt;$config['start_tag'] = "&lt;b&gt;"; // where you want to start grabbing&lt;br /&gt;$config['end_tag']   = "&lt;/b&gt;"; // where you want to stop grabbing&lt;br /&gt;$config['show_tags'] = 0; // do you want the tags to be shown when you show the html? 1 = yes, 0 = no&lt;br /&gt;&lt;br /&gt;class grabber&lt;br /&gt;{&lt;br /&gt;	var $error = '';&lt;br /&gt;	var $html  = '';&lt;br /&gt;	&lt;br /&gt;	function grabhtml( $url, $start, $end )&lt;br /&gt;	{&lt;br /&gt;		$file = file_get_contents( $url );&lt;br /&gt;		&lt;br /&gt;		if( $file )&lt;br /&gt;		{&lt;br /&gt;			if( preg_match_all( "#$start(.*?)$end#s", $file, $match ) )&lt;br /&gt;			{				&lt;br /&gt;				$this-&gt;html = $match;&lt;br /&gt;			}&lt;br /&gt;			else&lt;br /&gt;			{&lt;br /&gt;				$this-&gt;error = "Tags cannot be found.";&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;		else&lt;br /&gt;		{&lt;br /&gt;			$this-&gt;error = "Site cannot be found!";&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	function strip( $html, $show, $start, $end )&lt;br /&gt;	{&lt;br /&gt;		if( !$show )&lt;br /&gt;		{&lt;br /&gt;			$html = str_replace( $start, "", $html );&lt;br /&gt;			$html = str_replace( $end, "", $html );&lt;br /&gt;			&lt;br /&gt;			return $html;&lt;br /&gt;		}&lt;br /&gt;		else&lt;br /&gt;		{&lt;br /&gt;			return $html;&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$grab = new grabber;&lt;br /&gt;$grab-&gt;grabhtml( $config['url'], $config['start_tag'], $config['end_tag'] );&lt;br /&gt;&lt;br /&gt;echo $grab-&gt;error;&lt;br /&gt;&lt;br /&gt;foreach( $grab-&gt;html[0] as $html )&lt;br /&gt;{&lt;br /&gt;	echo htmlspecialchars( $grab-&gt;strip( $html, $config['show_tags'], $config['start_tag'], $config['end_tag'] ) ) . "&lt;br&gt;";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 05 Jul 2006 14:39:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2245</guid>
      <author>mrwhale (Paul Janaway)</author>
    </item>
  </channel>
</rss>
