Jump to content

[SOLVED] Fread and fwrite etc.


marklarah

Recommended Posts

Okay. Im making a simple web editor.

Code so far.

<?
function read($name){
$size = filesize($name);
if ($size != 0){
$F = fopen($name,"r");
$data = fread($F, $size);
fclose($F);
if ($data != ""){
print $data;
}else{
print "";
}
}else{
print "";

}
}

function write($name, $content){
$W = fopen($name, 'w');
fwrite($W, $content); 
fclose($W);
}

if (isset($_POST['cont'])){
$cont = nl2br($_POST['cont']);
write("test2.php", $cont);

echo '<p align="center">Saved!</p><br>';
}


echo '<center>';
echo '<form action="" method="POST">';
echo '<textarea cols="125" rows="40" name="cont">';
read("test2.php");
echo '</textarea><br>';
echo '<input type="submit" value="Save"></form>';
echo '</center>';
?>


 

Nothing particularly wrong. (was using nl2br)

The only thing is, I see in the textarea, <br> etc. How can I make it so when there are linebreaks they show up normally and such?

 

http://awesomealpha.com/test4.php

 

You can see it here.

 

Link to comment
https://forums.phpfreaks.com/topic/111417-solved-fread-and-fwrite-etc/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.