[Sun, 11 Feb 2001] Sterling Hughes said:
>
> > elixer Sat Feb 10 18:38:40 2001 EDT
> >
> > Modified files:
> > /php4/ext/standard file.c file.h
> > Log:
> > Fix for bug #4556
> > # This is pretty much a total rewrite of get_meta_tags using a simple
> > # handwritten tokenizer. It might be overkill, but it works.
>
> I'd say this is news worthy...
>
> Can you add an entry into the NEWS file.
I agree. However, on first glance, it only seems to grab the meta-tags
that have the NAME/CONTENT attributes, not the HTTP-EQUIV/CONTENT
attributes. This was a major drawback of the original code (IMHO).
I wrote my own get_metatags function in PHP. Find the code below. If
someone likes this and wants to convert it into C ...
<?php
function get_metatags($url) {
if (substr($url,0,7)=='http://') {
$url = substr($url,7);
}
if( !($fp = fopen('http://'.$url, 'r')) ) {
return false;
} else {
$file = '';
while (!feof($fp) && !stristr($file,'</head>') ) {
$file.= fgets($fp, 80);
}
fclose($fp);
$file = str_replace("\r", '', $file);
$file = str_replace("\n", '', $file);
$result = array();
preg_match_all('/<meta(.+?)>/i', $file, $temp);
if (is_array($temp[1])) {
foreach($temp[1] as $key=>$match) {
$t = $n = $c = '';
if (preg_match('/name=("|\')(.*?)\\1/i', $match, $b)) {
$t = 'NAME';
$n = $b[2];
} else if (preg_match('/http-equiv=("|\')(.*?)\\1/i', $match, $b)) {
$t = 'HTTP-EQUIV';
$n = $b[2];
}
if (preg_match('/content=("|\')(.*?)\\1/i', $match, $b)) {
$c = $b[2];
}
if ($t && $n && $c) {
$result[] = array(
'type' => $t,
'meta_name' => $n,
'meta_content' => $c
);
}
}
}
return $result;
}
}
?>
- Colin
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]