View Full Version : Reading Remote Page Data??

09-16-2005, 10:46 PM
I found this script on http://ca3.php.net/get_meta_tags,

But i'm having trouble making it working,

$title = "";
if ($fp = @fopen($_REQUEST['url'], 'r' )) {

$cont = "";

// read the contents
while( !feof( $fp ) ) {
$buf = trim(fgets( $fp, 4096 )) ;
$cont .= $buf;

// get tag contents
@preg_match( "/<title>([a-z 0-9]*)<\/title>/si", $cont, $match );

// tag contents
$title = strip_tags(@$match[ 1 ]);
echo $title;

it doesn't seem to bring back any data,

anyone have any ideas why this is not working?

thanks in advance for your time!

09-17-2005, 03:26 AM
Try using fsockopen()

09-17-2005, 03:30 AM
Change this statement:

@preg_match( "/<title>([a-z 0-9]*)<\/title>/si", $cont, $match );
to this:

@preg_match("|<title>(.*)</title>|s", $cont, $match );

09-17-2005, 05:29 AM
There is nothing wrong with your code , works fine for me as-is

2 possibles,

1) you do not have fopen wrappers enabled in your php.ini
2) the page you are trying to parse simply does not allow these types of remote requests

09-19-2005, 03:26 PM
thanks vinyl-junkie!
that fixed it;-)


09-19-2005, 03:41 PM
ah ok,
found one little problem,

I've found that alot of pages seem to have the title in CAPS, not sure if this is something done by the software used to make the pages or not,

but is there anyway to make this line read both upper and lower case titles?

@preg_match("|<TITLE>(.*)</TITLE>|s", $cont, $match );

@preg_match("|<title>(.*)</title>|s", $cont, $match );

thanks again for your time!

09-19-2005, 05:00 PM
@preg_match("|<title>(.*)</title>|si", $cont, $match );

09-19-2005, 05:50 PM
ah, simple as at;-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum