Jump to content

Recommended Posts

I was trying to make an HTML editor for my webpage in PHP.  First I had to make a script to display what is in the HTML documents, and in doing so, I encountered a problem.

 

Whenever I use fgets() to read a line out of any document with >'s or <'s, it just doesn't display anything.

And since HTML is obviously going to have a lot of <'s or >'s, this makes it hard to view and edit HTML files.

Do I need another function to read and write in files with these signs or is there some other way to use fgets()?

 

Here's a little bit of the code I was using. Maybe it's my fault it's not working? ???

<html><body>
<?php
$here = "makey-makey, eggs and bakey";
$filename = $_POST["filename"];


   $fr = fopen($filename, 'r');
       if(!$fr) {
fclose($fr);
      $fr = fopen($filename,'w');
      if(!$fr) {
         echo "Could not create the counter file!";
         exit;
      }
      fputs($fr, $here);
      fclose($fr);
} else {
      $line = fgets($fr, 1024);
	echo $line;
     fclose($fr);
      
   }
?>

</body></html>

Link to comment
https://forums.phpfreaks.com/topic/84199-reading-files-with-s-or/
Share on other sites

The problem is that if there are tags in the text, the browser believes they are HTML tags, and gets confused.

 

You need to use the htmlentities() function. It will change tags,quotes,symbols etc to their relevant HTML character code.

 

 

Awesome! ;D

I've got it displaying right, as in, it looks exactly like what's in the file. But then I have it use fputs() to write the revised version back to the file. But when it writes it back, all the quotes get slashes in front of them, like (\").

 

First I have the html file go through

htmlentities($text, ENT_QUOTES);

and be displayed. (The display looks exactly right.)

then it is written back to the file through

html_entity_decode($text, ENT_QUOTES);

but it is written having slashes before any quotes.

How do I fix this?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.