Jump to content

Recommended Posts

hello,

 

I am trying to create a simple text editor that when used 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 but im not sure! Please can someone revise this so i can use paragraphs of text succesfully?

 

:Editor Code:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #6191c2;
}
-->
</style>
<SCRIPT language="Javascript">
function selectit(input){
document.formname.news.value+=input
}
</SCRIPT>


<link href="rotary.css" rel="stylesheet" type="text/css" />
</head>

<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>

 

:This is how i display the .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 in advance if anyone can help me with this one!

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.