php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14623 get_meta_tags only looks in begin of file
Submitted: 2001-12-20 10:59 UTC Modified: 2001-12-22 12:59 UTC
From: jeroen at zwolnet dot com Assigned: elixer (profile)
Status: Closed Package: Strings related
PHP Version: 4.0.6 OS: linux
Private report: No CVE-ID: None
 [2001-12-20 10:59 UTC] jeroen at zwolnet dot com
get_meta_tags() seems to look only in the beginning of a file, meaning that e.g. if there is a lot of PHP code before the HTML header it will return nothing ...

Tested using get_meta_tags() on local files with about 9000 characters of PHP code before HTML HEADER.

Might be by design (speed), but then a warning is needed in doc: when adding working code, things (get_meta_tags()) stop working ...

Workaround: if possible move code after header or if not include a file :(

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-20 19:34 UTC] elixer@php.net
Can you please provide me with a small example of a file that get_meta_tags is failing on? The only time I am seeing this fail is if the text "</head" appears in the "working code" that you mention.

Sean
 [2001-12-21 05:29 UTC] jeroen at zwolnet dot com
<?

$s = "
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
... repeat this for about 110 lines of 80 'x'-es
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
";

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Failing get_meta_tags</title>
  <META NAME="subject" CONTENT="mySubject">
  <META NAME="keywords" CONTENT="myKeywords">
  <link rel="stylesheet" href="mysheet.css">
</head>

<body>
GET_META_TAGS:
<?
print_r( get_meta_tags( $HTTP_SERVER_VARS["PATH_TRANSLATED"]));
?>
</body>
</html>

 [2001-12-21 05:31 UTC] derick@php.net
Just a note... why would you want to do get_meta_tags on a non parsed file? I think it's makes way more sense to use g_m_t on a parsed file.

Derick
 [2001-12-21 05:48 UTC] jeroen at zwolnet dot com
The way I use it is quite different:

When a file is parsed it is 'wrapped': a prepended wrapper opens the file and layouts it.
Based on the meta tags a layout is choosen, menus added, header defined, etc.
This way the content exists out of plain HTML files that are build into the vieuwed pages when parsed.
(That can differ for showing, printing, spiders, ... all with the same content - that is easy to maintain even by dummies :).)

Jeroen.



 [2001-12-21 19:15 UTC] elixer@php.net
That example works fine here from the local CVS.  I don't think it has anything to do with PHP code being at the top of the page.  My wager is that you have _useful_ code that is breaking get_meta_tags, my guess is that the code contains the string "</head" in it somewhere.  Does this example piece of code actually not work on your setup?  All it seems to do is waste memory :)

Sean
 [2001-12-22 06:20 UTC] jeroen at zwolnet dot com
The code example shows the problem on my PHP 4.0.6 (redhat distr) - if you add the 110 lines print_r() shows an empty array, if you delete half of it the headerinfo is there.
Yes it is a memory eater, but the only purpose was to have a reproducable and simple example ... next time I will make a usefull example - telling jokes or something :).
If you look in the C source - is the whole file been read?
Can the # of bytes read be os/config (default blocksize)dependent?
Have you tried it with more memory eating xxx's?
Or it might be solved in 4.1.0 (CVS)?

Jeroen
 [2001-12-22 12:59 UTC] elixer@php.net
When I wrote "useful code" I was assuming that something in your working code was causing get_meta_tags() to stop parsing the document.

I have since downloaded and tested with 4.0.6 and 4.1.0.  I have the same problem on 4.0.6 on my redhat box.  4.1.0 seems to have fixed the problem and the latest CVS also works properly.

Closing this as its since been fixed.

Sean
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC