php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20918 fgetss() does not work
Submitted: 2002-12-10 03:01 UTC Modified: 2003-01-02 18:44 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ploter at gmx dot ch Assigned:
Status: No Feedback Package: Output Control
PHP Version: 4.3.0RC2 OS: win32
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
7 + 48 = ?
Subscribe to this entry?

 
 [2002-12-10 03:01 UTC] ploter at gmx dot ch
hello 
i wrote a script, that reads a few htmlpages with the function fgetss(), who strips away the html code. this works propperly in the php-version (php.4.2) 

but with php4.3 something goes wrong and i cant get no output from the function fgetss(). here are the code.
i hope this is a serious problem and it was helpful for you to report this... greets timon

<?php
// Liest aus den HTML -Dateien den Text aus
// und strukturiert ihn für die Datenbank.

$fh = opendir("html/") or die("cant read from ./html");
$x = 0;
while($file = readdir($fh)) {
	if($file == '.' || $file == '..') continue;
	$files[$x++] = $file;
	}	
closedir($fh);

echo sizeof($files)." HTML-Dateien ausgelesen...\n";

sort($files);

foreach($files as $file) {
	$fh = fopen("html/$file",'r');
	while($line = fgetss($fh,filesize("html/$file"))) {
		$raw_txt .= zeileputzen($line);
		}
	fclose($fh);
	}
	
echo sizeof($files)." Dateien wurden geparst...\n";

$fh = fopen('raw.txt','w+');
fputs($fh,$raw_txt);
fclose($fh);

echo "...und in die Datei <a href=\"raw.txt\">raw.txt</a> geschrieben...\n";

function zeileputzen($zeile) {
	// Tabulatoren, &nbsp;, Linktext usw raus...
	$zeile = str_replace("\t",'',$zeile);
	$zeile = str_replace("nach oben",'',$zeile);
	$zeile = str_replace("&nbsp;",'',$zeile);
	$zeile = preg_replace("/^ */",'',$zeile);
	
	if(preg_match("/^LvH-Umfeld/",$zeile)) {$zeile = '';}
	if(preg_match("/^Umfeld/",$zeile)) {$zeile = '';}
	if(preg_match("/^Personen/",$zeile)) {$zeile = '';}
	if(preg_match("/^- \w/",$zeile)) {$zeile = '';}
	$zeile = preg_replace("/^\W ?/","",$zeile);
	$zeile = preg_replace("/(B: )/","\n@B: ",$zeile);
	$zeile = preg_replace("/(Br: )/","\n@Br: ",$zeile);
	$zeile = preg_replace("/(K: )/","\n@K: ",$zeile);
	
	$zeile = preg_replace("/(B: )(\n)/",'B: ',$zeile);
	$zeile = preg_replace("/(Br: )(\n)/",'Br: ',$zeile);
	$zeile = preg_replace("/(K: )(\n)/",'K: ',$zeile);
	
	return $zeile;
	}
	


$fh = fopen("raw.txt",'r') or die("unable to read from raw.txt");
$raw_txt = fread($fh,filesize('raw.txt'));
fclose($fh);

echo "raw.txt ausgelesen\n";

$pieces = explode(chr(10),$raw_txt);
$f = 0;
foreach($pieces as $lines) {
	if(strlen($lines) == 0) { $f++; }
	if(strlen($lines) > 2) { $f = 0; }
	if($f > 10) { 
		$new_buffer .= '###';
		$f = 0;
		}
	echo " :: line -> $lines\n";
	$new_buffer .= $lines."\n";
	}

$f_pieces = explode('###',$new_buffer);
	
unset($new_buffer);

foreach($f_pieces as $l) {
	echo strlen($l);
	if(preg_match("/[A-Za-z0-9]/",$l)) {
		$f_lines = explode(chr(10),$l);
		$new_buffer .= "***";
		foreach($f_lines as $f) {
			if(!strlen($f)) { continue; }
			$f = trim($f);
			$new_buffer .= trim($f)."\n";
			}
		}
	}	
	
$fh = fopen('formatted.txt','w+');
fwrite($fh,$new_buffer);
fclose($fh);

echo "<a href=\"formatted.txt\">formatted.txt</a> geschrieben!\n";
echo "<a href=\"formattedtxt2mysql.php\">text in db eintragen...</a>\n";
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-10 05:31 UTC] hholzgra@php.net
please provide a *short* example showing the problem,
and add expected and actual output ...
 [2003-01-02 18:44 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2003-02-02 03:51 UTC] airtravel at anet dot ne dot jp
I experience similar issue.
fgetss function of PHP4.3.0 doesn't work in any way.
strip_tags(fgets()) works without any problem.

Scripts are working fine with <PHP4.2.3.
I experience the same issue with both on RedhatLinux7.2 and 7.3.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Jan 18 03:03:35 2022 UTC