Text editor code help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clay210
Forum Newbie
Posts: 5
Joined: Wed Jun 11, 2008 12:42 pm

Text editor code help

Post by clay210 »

I'm new to PHP and to this forum so any help with that in mind is appreciated.

Problem: I am writing a simple text editor using the fopen, fwrite, fclose and get_contents commands.

I have succeeded in getting the window to come up and drop in the existing text to edit but it is not saving. I am wondering if it has something to do with the mode I am using for fopen. I tried a couple other modes like 'a', 'a+' and 'r+' but am not having any luck. Here is my code:

//this is the get contents file
<?php
$filename = "../basictext.php";
$contents = file_get_contents($filename);?>


<form method="post" action="process.php">
<textarea cols="75" rows="30" name="content">

<?php echo $contents;?>

</textarea><br>
<input type="submit" name="Save" value="SAVE"></p>
</body>


//this is the processor
<?php
$contents = $_POST['contents'];
$filename = "../basictext.php";
$fp = fopen($filename, 'w');
fwrite($fp, $contents);
fclose($fp);
?>
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: Text editor code help

Post by nowaydown1 »

The element on your form name is called 'content', but your processing file references 'contents'.
clay210
Forum Newbie
Posts: 5
Joined: Wed Jun 11, 2008 12:42 pm

Re: Text editor code help

Post by clay210 »

Thanks.

It's always something simple.
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: Text editor code help

Post by nowaydown1 »

Always helps to have another set of eyes. Welcome to the forum!
clay210
Forum Newbie
Posts: 5
Joined: Wed Jun 11, 2008 12:42 pm

Re: Text editor code help

Post by clay210 »

Thanks. Looking forward to learning more.

This editor is really stripped down. It basically edits the code.

Where would I start if I want to make an editor that edits the text and have to edit the code? Kind of like this reply window with the B, i, etc.
clay210
Forum Newbie
Posts: 5
Joined: Wed Jun 11, 2008 12:42 pm

Re: Text editor code help

Post by clay210 »

another issue.

If I refresh the get_contents page it adds a bunch of slashes //// to the code and sometimes in the text.

seems to be where there are spaces

any reason why?
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: Text editor code help

Post by nowaydown1 »

For the bold, italics stuff, you would want to look at using javascript that will dynamically insert/modify stuff in your textbox. As for slashes being added, I would guess its because magic_quotes_gpc is probably enabled in your php.ini. For information on how to turn it off, see:

http://us2.php.net/manual/en/security.m ... abling.php
Post Reply