Jump to content

Text editor


Schlo_50

Recommended Posts

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!

 

 

Link to comment
https://forums.phpfreaks.com/topic/52613-text-editor/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.