Text Formatting problem

My site is known for a PHP based source page which creates a fresh file on the site. My problem is the fact when I submit something coming from a text area, PHP removes many of the line breaks in advance of adding it into a file. So that as you move description I set up is properly formated, one that viewers read is often a single long section. Is there any tool for fixing that

Another problem is the fact if I put a " on the name of your file, fopen() automatically adds a backslash just before it. (ie Bob’s stuff results in being Bob/’s stuff)

Anyone know why when you can stop either of these from happening

With thanks,
Theodore

The backslash thing refers to this PHP receive:
$content = stripslashes($content);
You need to use that before everyone save it towards file.

The line breaks is really a little tougher to resolve.
This actually depends on how you edit the content.

I usually do it this way…. but it’s my particular preference.
This is to save your content… textarea from a form.

PHP:


< php

//    You  have  a  whole  textarea  from  a  form ...
//    The  name  of  the  form  variable  is  "textarea".

$textarea  $_POST'textarea';

//  Save  the  content 
$url="page1. txt";   //  whatever  you  name  the  content  text  file
$newtext=stripslashes($textarea);   //  remove  the  slashes    \'
$newtext  str_replace("< ",   "",   $newtext);   //  remove  any  PHP  script  references
$newtext  str_replace("> ",   "",   $newtext);   //  remove  any  PHP  script  references
$newtext  nl2br($newtext);   //  Change  all  "new  line"  carriage  returns  to  < br  />
//  open  the  text  file  and  save  it  most.
$fh  fopen($url,   'w')  or  die("can't  open  file");
fwrite($fh,   $newtext);
fclose($fh);  
header  ("location:   list. php");   //  return  back  from  where  you  came

>


Now, after you display it pertaining to editing (in a textarea over a form), you need
in order to convert the < br /> to " new lines"…

PHP:


< php

//  Your  text  file
$url  "page1. txt";

//  Get  page
$data  implode("",   file($url));  

//  Convert  all  < br>   to  "new  lines".
//  There  is  not  a  built-in  PHP  function  to  do  the following,   so  I  call  my  own  function  (see  below).
$newdata  br2nl($data);

//  form  stuff  here ....
//  the  < br> 's  disappear  and  now  become  textarea  "new  lines"  or  "carriage  returns".
echo  "< textarea  name='textarea'  rows='25'  cols='80'> $newdata< /textarea> ";

//  A  function  to  convert  < br>   and  < br  />   back  to  "new  lines".
function  br2nl($str
return 
preg_replace('=< br  */> =i',   "",   $str);

>


With thanks,
Of which works great.
Theodore.

This entry was posted in Web Design and tagged , , , , , , , , , . Bookmark the permalink.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *