[FX.php List] Keeping Carriage Returns in Textarea submissions

Steve Winter steve at bluecrocodile.co.nz
Fri Aug 10 00:59:30 MDT 2007


Hi Jonathan and Kevin, 

I think Kevin, that function will work fine for half of Jonathan's
requirements, the 'post the data back on the web page' (though wouldn't 

	echo '<p>'.nl2br($theData).'</p>';

have just the same result...?)

However for the other half of the requirements, if you use that function in
a textarea to allow editing Jonathan, then it's going to display <p>, <br />
and </p> tags within that textarea, then store those back in the db, then
end up in something of a mess next time it gets displayed...

For your text area you should just be able to use echo the data straight
into the text area and the newline characters stored in FMP will be rendered
out giving the correct display in the text field...

Cheers
Steve

-----Original Message-----
From: fx.php_list-bounces at mail.iviking.org
[mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Kevin Futter
Sent: Friday, 10 August 2007 7:37 a.m.
To: FX.php Discussion List
Subject: Re: [FX.php List] Keeping Carriage Returns in Textarea submissions

On 10/8/07 2:06 PM, "Jonathan Schwartz" <jschwartz at exit445.com> wrote:

> Nope.  That was the question, all right.
> 
> That was easier than I thought.  I'd love to have the function.
> 
> Thanks
> 
> J

Hi Johnathan,

Try this out:

// function to replace line breaks in FM output with <br /> or <p> elements

function formatDesc($input)
{
$br = chr(10); // single line feed character (LF)
$p = "<br />\n<br />\n";
$badChars = array($p, "& ");
$goodChars = array("</p>\n\t\t<p>", "&amp; ");
$text = str_replace($br, "<br />\n", $input); // replace LF with <br />

$description = str_replace($badChars, $goodChars, $text);
echo "<p>" . $description . "</p>\n";
}

Modify it as you need to!

-- 
Kevin Futter
Webmaster, St. Bernard's College
http://www.sbc.melb.catholic.edu.au/




############################################################################
#########
This e-mail message has been scanned for Viruses and Content and cleared 
by MailMarshal
############################################################################
#########

This e-mail and any attachments may be confidential. You must not disclose
or use the information in this e-mail if you are not the intended recipient.
If you have received this e-mail in error, please notify us immediately and
delete the e-mail and all copies. The College does not guarantee that this
e-mail is virus or error free.  The attached files are provided and may only
be used on the basis that the user assumes all responsibility for any loss,
damage or consequence resulting directly or indirectly from the use of the
attached files, whether caused by the negligence of the sender or not. The
content and opinions in this e-mail are not necessarily those of the
College.

_______________________________________________
FX.php_List mailing list
FX.php_List at mail.iviking.org
http://www.iviking.org/mailman/listinfo/fx.php_list

No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.11.10/943 - Release Date: 8/08/2007
5:38 p.m.
 

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.11.10/943 - Release Date: 8/08/2007
5:38 p.m.
 




More information about the FX.php_List mailing list