Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

fgetss failure ?

Posted on 2013-01-10
3
Medium Priority
?
249 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 1000 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

704 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