Jump to content

Recommended Posts

I have a text area where large amounts of text can be added but when ever a carriage return occurs the new line isn't echoed properly, im trying to use str_replace to replcace \n for <br /> but the <br /> will not add to my home.txt file.

 

<?php
if ($_POST['Submit12'] == "Submit")
{
$file_name = "home.txt";
$open_file = fopen($file_name, "a+");
$file_contents= $_POST['title'] . '|' . $_POST['news'] ."\n";
$replace = str_replace("\n", "<br />", $file_contents);
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";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/53602-str_replace-help/
Share on other sites

Warning: Wrong parameter count for nl2br() in C:\apachefriends\xampp\htdocs\rotaryclub\homepagetry.php on line 84

 

 

 

<!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 /><br /></strong></span>  
  <?php

$a = "<img border=\"0\" src=\"images/bold.jpg\" width=\"25\" height=\"25\" alt=\"Bold\" onClick=\"selectit('<b>Text Here</b>')\"> ";

$b .= "<img border=\"0\" src=\"images/underline.jpg\" width=\"25\" height=\"25\" alt=\"Underline\" onClick=\"selectit('<u>Text Here</u>')\"> ";

$c .= "<img border=\"0\" src=\"images/link.jpg\" width=\"25\" height=\"25\" alt=\"Hyperlink\" onClick=\"selectit('<url>http://www.site.com>Site Name</url>')\"> ";

$d = "<img border=\"0\" src=\"images/para.jpg\" width=\"100\" height=\"25\" alt=\"New Paragraph\" onClick=\"selectit('<br><br>')\"> ";

?><?php
if ($_POST['Submit12'] == "Submit")
{
$file_name = "home.txt";
$open_file = fopen($file_name, "a+");
$file_contents= $_POST['title'] . '|' . $_POST['news'] ."\n";
nl2br("\n\r", "<br />");
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" />
  <br /><br /><?php
echo("$a");
echo("$b");
echo("$c");
echo("$d");
?>
  <p>
    <textarea name="news" cols="50" rows="15" id="news" wrap="hard"></textarea>
  </p>
  <p>
    <label>
    <input type="submit" name="Submit12" value="Submit" />
    </label>
</p>
</form>
</label>
<span class="rotary">
<?php
  
  $file = file("home.txt");
  foreach($file as $key => $val){
  $data[$key] = explode("|", $val);
  
  $title = $data[$key][0];
  $news = $data[$key][1];

  $outa = "<br><b><u>$title</u></b><br>"; 
  $outb = "$news<br><br>";
  $outc = "____________________________________";
  nl2br("\n\r", "<br />");
   print( $outa );
   print( $outb );
   print( $outc );
   
}
?>
</span>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/53602-str_replace-help/#findComment-264983
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.