Page 1 of 1

Read text that were saved with WYSIWYG

Posted: Wed Jun 24, 2009 1:50 am
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?

Re: Read text that were saved with WYSIWYG

Posted: Wed Jun 24, 2009 4:50 pm
by Eric!
Are the return codes being added when you save the file?

Re: Read text that were saved with WYSIWYG

Posted: Thu Jun 25, 2009 7:07 am
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>