0

Hi,

Code below doesn't work for a file contains HTML content? How do we solve this issue?

Result must be <span but it dispays blank screen.

Thanks in advance

Content of index.txt

<span class="mw-headline" id="Zero"><a href="/wiki/Zero" title="Zero">Zero</a></span></h2>

PHP to read the file

<?php
$handler = fopen('index.txt','r');

while ($line = fgets($handler))
{
    echo substr($line, 0, 4); exit;
}

fclose($handler)
?>
3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by veledrom
1

Well it probably will display a blank screen '<spa' shouldn't give any screen output. What about browser view source?

Is this the code you want to run? Or is it for testing purposes? As the 'while' makes little sense if you're exiting after the first line.

BTW - if you have a blank line at the beginning of the file, it will show a blank.

0

I think it will never work when I try to echo html code in a page unless trying to echo it into textarea etc.

I'm exiting because the txt file many lines so I was just testing with one line only.

In browser code view, <spa is being printed correctly.

0

syntax

<?php $handler = fopen('index.txt','r');
while ($line = fgets($handler)){ echo '<br>'.htmlentities($line);}
fclose($handler); ?>

the original works, without the substring and exit, to generate functional html,
this version generates displayable html

Edited by almostbob

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.