Solved

fgetss failure ?

Posted on 2013-01-10
3
228 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
Comment Utility
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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
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
Comment Utility
Thanks, needed to parse first with  preg_replace('/<!--,*-->/s' "", $var);
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now