Solved

fgetss failure ?

Posted on 2013-01-10
3
245 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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 …

626 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