php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22008 fgetss : 0 vs false, html on multiple lines
Submitted: 2003-02-02 04:06 UTC Modified: 2003-05-04 06:49 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: airtravel at anet dot ne dot jp Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.3.0 OS: all
Private report: No CVE-ID: None
 [2003-02-02 04:06 UTC] airtravel at anet dot ne dot jp
fgetss() funcion of PHP4.3.0 doesn't work in any way.
strip_tags(fgets()) works fine.

Scripts are working fine with <PHP4.2.3.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-02 04:11 UTC] airtravel at anet dot ne dot jp
Also bug report confirmation page(report.php) doesn't show up correctly because <TITLE> tag added in the middle of the body.

Try to submit something about 'fgetss' to reproduce this bug report page issue.
 [2003-02-02 14:44 UTC] iliaa@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

I think the problem you are seeing may stem from incorrect usage of the fgetss() function. For that reason I am including a sample of a working code for this function below
<?php
 $fp = fopen("http://bugs.php.net/bug.php?id=22008", "r");
 while (($line = fgetss($fp, 4096)) !== FALSE) {
  echo $line;
 }
 fclose($fp);
?>

Note that the output of fgetss gets compared to false, this is very important because it is quite likely that fgetss() will return 'blanks' if the line only contains HTML data.
 [2003-02-02 15:41 UTC] philip@php.net
That or maybe a problem existed because it only gets/strips one line at a time which makes dealing with html tags spanning multiple lines not-so-good.  So using this fgetss() example script vs strip_tags(file_get_contents($url)) will yield different results.

Reclassifying as a doc problem for fgetss():
a) Add the 0 vs false entity
b) Add a warning regarding spanning html tags; offer an alternative
 [2003-02-02 15:46 UTC] philip@php.net
c) Add a <note> regarding the 'blank lines' comment from Ilia.

I don't think strip_tags() needs this <note> but maybe it does (doubtful).
 [2003-02-02 21:08 UTC] airtravel at anet dot ne dot jp
Thank you for your comments.
I found this problem only occurs when parsing specific html.

Please try the following URL to see my problem.
Thank you.

<?php
 $fp = fopen("http://adds.aviationweather.gov/projects/adds/metars/index.php?metarIds=ksfo", "r");
 while (($line=fgetss($fp, 4096))!==FALSE) {
  echo $line;
 }
 fclose($fp);
?>

<?php
 $fp = fopen("http://adds.aviationweather.gov/projects/adds/metars/index.php?metarIds=ksfo", "r");
 while (($line = strip_tags(fgets($fp, 4096)))!==FALSE) {
  echo $line;
 }
 fclose($fp);
?>
 [2003-02-02 22:06 UTC] airtravel at anet dot ne dot jp
This is something to do with <!DOCTYPE>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
seems to be causing problem.

Again PHP4.2.3 or earlier treats this without problem.
 [2003-02-03 14:59 UTC] iliaa@php.net
I've tried the latest CVS and tried to fetch the page you've specified. As far as I can tell the function had worked correctly, only non-html output was displayed.

P.S. Philip the fgetss() function is supposed to handle tags that span multiple lines, so that should not be a problem.
 [2003-02-18 15:50 UTC] phpdig at toiletoine dot net
This code :
<?php
print "Test one :".strip_tags('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Some title</TITLE>
<META content="text/html; charset="ISO-8859-1" http-equiv=Content-Type>')
."<br>";

print "-----------<br>";

print "Test two :".strip_tags('<DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Some title</TITLE>
<META content="text/html; charset="ISO-8859-1" http-equiv=Content-Type>')
."<br>";

print "-----------<br>";

print "Test three :".strip_tags('<!FOO BAR>
real text
<br>')
."<br>";

?>

Gives me :

Test one :
-----------
Test two : Some title 
-----------
Test three :


Any "<!SOMETHING..." strips all !!
 [2003-05-03 05:44 UTC] moriyoshi@php.net
This bug may be caused by the less stateful strip_tags implementation, which should be rewritten with something like re2c in the future anyway.

 [2003-05-04 06:49 UTC] moriyoshi@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

The quick fix will be in 4.3.2.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC