Jump to content

retrieving description from remote url


jakebur01

Recommended Posts

I am trying to capture the description from a remote url. I am currently retrieving the info between <head> and </head>. How do I get the ***<meta name="Description" content=""> **** information stored into a variable?

$config['url']       = "http://www.walmart.com"; 
$config['start_tag'] = "<head>"; 
$config['end_tag']   = "</head>"; 
$config['show_tags'] = 1; 

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;

foreach( $grab->html[0] as $html )
{
echo htmlspecialchars( $grab->strip( $html, $config['show_tags'], $config['start_tag'], $config['end_tag'] ) ) . "<br>";
}

Link to comment
https://forums.phpfreaks.com/topic/103786-retrieving-description-from-remote-url/
Share on other sites

Ok, I've stored the outputing html into a variable named $sammy. How do I seperate the  <meta name="Description" content="">  from the variable?

 

Thanks,

 

Jake

 

foreach( $grab->html[0] as $html )
{
$sammy= htmlspecialchars( $grab->strip( $html, $config['show_tags'], $config['start_tag'], $config['end_tag'] ) ) . "<br><br>";
echo "$sammy";
} 

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.