Re: [PHP-CVS] cvs: php4 /ext/standard file.c file.h

2001-02-11 Thread Sterling Hughes


 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.

-Sterling


-- 
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]




Re: [PHP-CVS] cvs: php4 /ext/standard file.c file.h

2001-02-11 Thread Colin Viebrock

[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]




RE: [PHP-CVS] cvs: php4 /ext/standard file.c file.h

2001-02-11 Thread Sean R. Bright

Well, I was trying to fix one bug, not introduce others.  If you read the
documentation for get_meta_tags you will see that it returns an associative
array that is keyed by the value of the NAME attribute while the value is
the data within the CONTENT attribute.

If other members of the developers list would like to suggest a solution for
this problem, I would be more than happy to implement it.  Right now I don't
know how to add what you are asking for without breaking existing PHP code.

Sean

 -Original Message-
 From: Colin Viebrock [mailto:[EMAIL PROTECTED]]
 Sent: Sunday, February 11, 2001 10:52 PM
 To: Sterling Hughes
 Cc: Sean Bright; [EMAIL PROTECTED]
 Subject: Re: [PHP-CVS] cvs: php4 /ext/standard file.c file.h


 [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]




-- 
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]