Schlo_50 Posted May 23, 2007 Share Posted May 23, 2007 Hello, I am trying to create a simple text editor that when used, it adds the text to a .txt file. At the moment im having trouble with the formatting of the text in terms of new lines. If i write in one long sentence the positioning of the text is fine however if i try to use paragraphs extra lines are added in and then the code gets confused and makes parts of the paragraphs titles, shown in bold. I think it may be because of the "\n"; part of my code and then the explode '|' but im not sure! Please can someone revise this so i can use paragraphs of text succesfully? It's taken me ages to get to this stage and it would be cool if someone could just paste in their example. EDITOR: <body> <label> <p><span class="rotary"><strong>Text Editor<br /></strong></span> <?php $prnt = "<img border=\"0\" src=\"images/bold.jpg\" width=\"25\" height=\"25\" alt=\"Bold\" onClick=\"selectit('<b>Text Here</b>')\"> "; $prnt .= "<img border=\"0\" src=\"images/underline.jpg\" width=\"25\" height=\"25\" alt=\"Underline\" onClick=\"selectit('<you>Text Here</you>')\"> "; $prnt .= "<img border=\"0\" src=\"images/link.jpg\" width=\"25\" height=\"25\" alt=\"Hyperlink\" onClick=\"selectit('<url>http://www.site.com>Site Name</url>')\"> "; ?> <?php echo("$prnt"); ?> <?php if ($_POST['Submit12'] == "Submit") { $file_name = "home.txt"; $open_file = fopen($file_name, "a+"); $file_contents= $_POST['title'] . '|' . $_POST['news'] ."\n"; fwrite($open_file, $file_contents); fclose($open_file); echo "<meta http-equiv=\"refresh\" content=\"0;URL=homepagetry.php\">"; echo "Form data successfully written to file"; } ?> </p> <form id="formname" name="formname" method="post" action=""> <p> <span class="rotary">Title:</span> <input type="text" name="title" /> <p> <textarea name="news" cols="85" rows="15" id="news"> </textarea> </p> <p> <label> <input type="submit" name="Submit12" value="Submit" /> </label> </p> </form> </label> DISPLAYING OF .TXT FILE: <body> Testing Text Formatting.. <br /> <br /> <br /> <?php $file = file("home.txt"); foreach($file as $key => $val){ $data[$key] = explode("|", $val); $title = $data[$key][0]; $news = $data[$key][1]; $outa = "<b><you>$title</you></b><br><br>"; $outb = "$news<br>"; print( $outa ); print( $outb ); } ?> </body> </html> Thanks for any help guys! Much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/52613-text-editor/ Share on other sites More sharing options...
MasterACE14 Posted May 23, 2007 Share Posted May 23, 2007 I think this would be an easier task to do in Visual Basic but if you really want to do it in PHP, go for it Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/52613-text-editor/#findComment-259686 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.