Create Grabber Using With Curl
<?
function html_to_array( $url, $element = null )
{
if( !( $data = file_get_contents( $url ) ) )
return false;
preg_match_all( '~<img.*?>(</img>)?~si', $data, $page['img'] );
preg_match_all( '~<div.*?>.*?[^<]</div>~', $data, $page['div'] );
preg_match_all( '~<style.*?>.*?[^<]</style>~', $data, $page['Inline_Css'] );
preg_match_all( '~<link.*?>~', $data, $page['Linked_Css'] );
preg_match_all( '~<meta.*?[^>]>~', $data, $page['Meta'] );
preg_match_all( '~<a.*?[^>].*[^<]</a>~', $data, $page['Link'] );
return !is_null( $element ) ? $page[ $element ] : $page ;
}
function display_links( $links, $htmlentities = true )
{
foreach( $links as $number => $link )
{
printf("Link number %d : [ %s ]<br />\n", $number + 1, $htmlentities ? htmlentities( $link ) : $link );
}
}
foreach( html_to_array( 'http://forums.digitalpoint.com' ) as $element => $html )
{
printf( "I see %d %s tags<br />\n",
count( $html[0] ),
str_replace('_', ' ', $element )
);
}
foreach( html_to_array( 'http://forums.digitalpoint.com', 'Link' ) as $links )
{
printf("I found %d links, here they are :<br />\n%s",
count( $links ),
display_links( $links )
);
}
?>
0 comments
Post a Comment