By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

How to detect a line break in a multiline textfield

P: n/a
Hi can someone give me the code to convert a line break in a multiline
textfield to a <br/tag ? It's something to do with CR LF but I can't
find the exact code anywhere.
Cheers,
Ciarán

Feb 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ciaran wrote:
Hi can someone give me the code to convert a line break in a multiline
textfield to a <br/tag ? It's something to do with CR LF but I can't
find the exact code anywhere.
Cheers,
Ciarán
nl2br
Feb 28 '07 #2

P: n/a
Hendri Kurniawan wrote:
Ciaran wrote:
>Hi can someone give me the code to convert a line break in a multiline
textfield to a <br/tag ? It's something to do with CR LF but I can't
find the exact code anywhere.
Cheers,
Ciarán
nl2br
Sorry, Need to clarify this.
nl2br converts line break to HTML br tag.
If you want to change from <br/tag to CRLF, do a str_replace instead.
I've no recollection any functions that will convert br tag to CRLF
(as far as i know anyway)

Hendri Kurniawan
Feb 28 '07 #3

P: n/a
Thanks for the reply Hendri. I got it sorted out using a simple find
and replace I found by searching for nl2br thanks to your second
post.

Converting textarea line breaks to <brin PHP
$result = str_replace(array("\r\n", "\r", "\n"), "<br />",
$thestring);

Converting <brto textarea line breaks in PHP:
$result= str_replace(array("<br/>", "<br>", "<br />"), "\n",
$thestring);

Hope this helps someone,
Ciarán

Feb 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.