Solved

fgetss failure ?

Posted on 2013-01-10
3
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML auto refresh to another site 4 28
Popup write two lines 3 22
deprecated mysql extensions 1 23
Check input text, Number 6 29
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

756 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