...

View Full Version : Reading Remote Page Data??



angst
09-16-2005, 11:46 PM
Hi,
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!
-Ken

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

vinyl-junkie
09-17-2005, 04: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 );

firepages
09-17-2005, 06: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

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

-Ken

angst
09-19-2005, 04: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!
-Ken

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

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

thanks!

-Ken



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum