hello,
I got a piece of code supposed to grab content from a remote page, this content is located between 2 defined html tags.
here is the code :
<?php
$config['url'] = $row_DetailRS1['CreatedUniqueID']; // url of html to grab
$config['start_tag'] = "<p>"; // where you want to start grabbing
$config['end_tag'] = "</p>"; // 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;
foreach( $grab->html[0] as $html )
{
echo htmlspecialchars( $grab->strip( $html, $config['show_tags'], $config['start_tag'], $config['end_tag'] ) ) . "<br>";
}
?>
Actually this code grabs the content from the page i am intterested in. However i don't want to take all the content from thi page, only the small intro...the small intro is located between the following html tag :
<p class="frist">intro text</p>
The problem here is the class of the <p> tag is not taken into account in this code.
Thanks for any suggestion
Yaz