Solved

fgetss failure ?

Posted on 2013-01-10
3
235 Views
Last Modified: 2013-01-14
fgetss appears to fail when it reads an unterminated html comment.
For example, the string:  "Get www.google. com <!-- HTTP/1.1"

I am reading from a file of lines, each of which contains some html.

If <!-- occurs without a terminating brace, the file processing is not completed.
How can this be fixed?

@$handle = fopen($filename, "r");

while (!feof($handle)) {

    $buffer = fgetss($handle, 4096);
     ...

Open in new window

0
Comment
Question by:pillmill
3 Comments
 
LVL 12

Accepted Solution

by:
sivagnanam chandrakanth earned 250 total points
ID: 38766244
I dont think there is a way to overcome with any of the PHP functions..
One way is to write a regular expression to find and remove unterminated comment, but thats is not going to be that easy
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 38769024
One clue to the "popularity" of this function is the complete absence of user-contributed notes in the online man page.  That alone would lead me to look elsewhere.
http://php.net/manual/en/function.fgetss.php

Can you please give us a small test data set that illustrates the issue?  Follow the guidance in http://sscce.org and show us a test case that we can modify.  I will try to show you how to get around the issue with a minimum of code changes.
0
 

Author Closing Comment

by:pillmill
ID: 38776678
Thanks, needed to parse first with  preg_replace('/<!--,*-->/s' "", $var);
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to fix Datetime in MySQL? 4 50
What's wrong with this PDO query? 5 27
PHP: Best way to scan folders and process files 10 40
Bootstrap 3 - Style a dropdown 1 12
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question