...

View Full Version : Problem



java001
02-20-2012, 01:39 PM
I have a problem - I made a code that allows me to read files in a textarea.
Now what I see in the text area is basically the source of the file :
http://img96.imageshack.us/img96/5720/dgdsgk.jpg (http://imageshack.us/photo/my-images/96/dgdsgk.jpg/)
And I want people to edit only their text, the problem is that people can see also the code. What I want it, is to look like this: so people could see everytext in the file that they uploaded in it's size, and decoration.
http://img269.imageshack.us/img269/6625/outputge.jpg (http://imageshack.us/photo/my-images/269/outputge.jpg/)
How can I do this ? I can't seem to understand this.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<?php
//file to read

$file = "C:\wamp\www\New Folder\cpl.php";

// file open

$fo = fopen("$file", "r") or die("Could not find '$file'!");

//read the file

$fr = fread($fo, filesize($file)) or die("Could not read '$file'!");

//close the file

$fc = fclose($fo) ;


?>
<center>
<textarea cols='118' name="txtbox" rows='15' class='textarea'><?php echo $fr; ?></textarea>
</center>
</body>
</html>

mlseim
02-20-2012, 01:47 PM
That's called RTF (Rich Text Formatting).
You need to use a script like TinyMCE ...
http://www.tinymce.com/

java001
02-20-2012, 02:18 PM
That's not it, I might use this script later, but now what i want is that in the textarea it will display only the text which in the file I want to read.
Can any one show me what to add to my script in order to achieve that?.

mlseim
02-20-2012, 03:07 PM
Call this script "edit.php" and see if it works for you ...



<?php
$action="";

if(isset($_POST['action'])){
$action=$_POST['action'];
}
if(isset($_POST['textarea'])){
$textarea=$_POST['textarea'];
}

$url = "C:\wamp\www\New Folder\cpl.php";
if (file_exists($url)) {
// do nothing
} else {
echo "File does not exist.";
exit;
}

// Get page
$data = implode("", file($url));

if($action=="save"){
$newtext=stripslashes($textarea);
$newtext = str_replace("<?", "", $newtext);
$newtext = str_replace("?>", "", $newtext);
$newtext = nl2br($newtext);
$fh = fopen($url, 'w') or die("can't open file");
fwrite($fh, $newtext);
fclose($fh);
header ("location: edit.php");
}
else{
echo"
<html>
<head><title>Text Editor</title>
<style>
body,html{
margin:0px auto;
width:700px;
text-align:center;
}
#content{
margin:0px auto;
width:700px;
}
#middle h1 {
color: transparent;
font-family:georgia;
font-size:12pt;
margin:0;
color: #dF9100;
padding:10px 0px 15px 0px;
text-align:left;
}
</style>
<body>
<div id='content'>
";

$ta=br2nl($data);

echo"
<a href='$return'><-- Return to Page</a><br /><br />
Make Changes and click \"Save Changes\" at the very bottom ...<br />
<form action='edit.php' method='post'>
<input type='hidden' name='action' value='save'>
<textarea name='textarea' rows='25' cols='80'>$ta</textarea>
<br />
<input type='submit' name='submit' value='Save Changes'>
</form>

<div id='middle' style='width:680px; text-align:left; padding-left:20px; border:1px solid #ccc;'>
";
echo"
</div>
</div>
</body>
</html>
";
}

function br2nl($str) {
return preg_replace('=<br */?>=i', "", $str);
}

?>



.

java001
02-20-2012, 06:32 PM
Thank you very much, this was very helpful to me.
One last question - when the file I want to edit opens I see it with it's tags <html> <?php etc. - is there an option to make only the text appear in the textarea ? and not the code ?
for example:
I have in the file this code:

<h1>Heading 1<h1>
<br />
<p>New content!</p>
<input type='submit' value='submit'/>
<br />
<img src='bla.jpg' width='500px'/>

I want to see in the textarea not the code above but it's output not the buttons nor images just the plain text:

Heading 1
New content!

mlseim
02-20-2012, 06:40 PM
You can strip HTML ....

But the problem is, when you edit the text and submit it for saving,
your HTML cannot be put back in. That's sort of the point I was making
in post #2. You want an actual "HTML text editor". That can't be done
without using some sort of mixed PHP/javascripting ... which is AJAX,
JQuery, things like that.

So, look at these google results and find some very simple editors, and some
more complicated ones. Some are simple javascripting.

http://www.google.com/search?q=php+simple+html+editor&btnG=Search

EDIT:
This one looks interesting (I haven't tried it though):
http://www.knowledgesutra.com/forums/topic/53278-create-a-simple-html-editor-with-php-and-javascript/


.

java001
02-20-2012, 06:42 PM
Thank you very much, I understand now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum