Read text that were saved with WYSIWYG

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
Murble
Forum Newbie
Posts: 11
Joined: Thu Feb 10, 2005 3:27 am

Read text that were saved with WYSIWYG

Post by Murble »

hi,
Im using WYSIWYG-Editor to allow my users to edit and save texts

when I save text to file and then read it, it ads "\n\n" to the output

this is because the text contains \n\n in it when the WYSIWYG saves it

I tried using those functions to read it correctly:

Code: Select all

 
$content = addslashes(preg_replace('`[\r\n]`','\n',$content));
$content = stripslashes ($content);
$content = str_replace("\n", "<br>", $content);
$content = nl2br($content);
 
but non helped,
I can not get reed of the \n\n


any suggestions?
Last edited by Benjamin on Wed Jun 24, 2009 10:36 am, edited 1 time in total.
Reason: Added [code=php] tags.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Read text that were saved with WYSIWYG

Post by Eric! »

Are the return codes being added when you save the file?
Murble
Forum Newbie
Posts: 11
Joined: Thu Feb 10, 2005 3:27 am

Re: Read text that were saved with WYSIWYG

Post by Murble »

problem solved!
this is how you should do it:

Code: Select all

 
 <head>
<script type="text/javascript" src="editor.js"></script>
</head>
 
<?php
    $nomanip = $_POST["editor1_content"]; //no text manipulation
    
 
    
    
                  // save the received post with no text manipulating
                 $f = fopen("11.dat" ,"w+");
                 fwrite($f,$nomanip);
                 fclose($f); 
                 chmod("11.dat",0600);
 
 
 
                    $fh = fopen("11.dat", 'r') or die("Can't open file");
                    if ($fh)
                    {
                        $theData = fgets($fh);
                        $text_content = "";
                        while ($theData)
                        {
                            $text_content .= $theData ;//$str; //$_POST["editor1_content"];
                            $theData = fgets($fh);
                        }
                        fclose($fh);
                        
                        //maniputations on text to show it on the page correctly
                        $yyy = $text_content;
                        $yyy = stripslashes ($yyy);
                        $yyy = nl2br($yyy);
                        $yyy = str_replace("<br />", "", $yyy);
                        echo $yyy;
                        
                    }
 
                    //in order to show in the editor correctly
                    $content = $text_content; 
                    $content = addslashes(preg_replace('`[\r\n]`','\n',$content));
                    $content = stripslashes ($content);
 
?>
 
<form action=3.php onsubmit="editor1.prepareSubmit()" method="post">
 
<script type="text/javascript">
    var editor1 = new WYSIWYG_Editor('editor1','<?php echo $content; ?>');
    editor1.display();
</script>
 
 
<input type=submit>
 
</form> 
 
 
 
Post Reply