
12-21-09, 15:03
|
|
vaguely human
|
|
Join Date: Jun 2007
Location: London
Posts: 2,519
|
|
Quote:
|
Originally Posted by lse123
How I grab the source of the web page (url) in a text var ?
|
The following grabs the source for a web page and splits it into urls and the text that goes with it. It's not perfect but I'm sure you can improve things if you want.
Code:
<?php
$start_url = "http://www.bikesandkites.com/";
# get the file contents
$str = @file_get_contents( $start_url );
# split it into parts where each contains a url
$links = spliti( "<a ",$str );
# for each part
for( $i=0;$i<count($links);$i++ ) {
# grab and clean up url
$url = ereg_replace( "\>.*", "", $links[$i] );
$url = eregi_replace( ".*href=", "", $url );
$url = eregi_replace( "http:..", "", $url );
$url = eregi_replace( " .*", "", $url );
# grab and clean up txt part of link
$txt = ereg_replace( "^[^>]*>", "", $links[$i] );
$txt = ereg_replace( "[<].*", "", $txt );
# print url and text
echo "url=$url txt=$txt\n";
};
?>
Quote:
|
Originally Posted by lse123
what if not html/htm but php/jsp/cfm...?
|
Why should that matter?
|
|