Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > replacing carriage returns with
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 2nd November 12:26
luna
External User
 
Posts: 1
Default replacing carriage returns with



how can i do this ?

eg someone types some data into a text area

eg

line1
line2
line3

i need to replace the carriage returns with a <b>

i know the syntax of the str replace command, just dont know the right code
for the
carriage return.

cheers

luna
  Reply With Quote


  sponsored links


2 2nd November 12:26
ian.h [ds]
External User
 
Posts: 1
Default replacing carriage returns with



On Tue, 19 Aug 2003 14:42:10 +0100 in
<message-id:bht97i$1si$1@newsg2.svr.pol.co.uk>

2 options, if you're using HTML (rather than XHTML), you can use the
simple 'nl2br()' built-in function:


$text = nl2br($text);


If you're using XHTML.. AFAIK, there is no built-in wrapper for this, so
you could use a function that I wrote a while back:

function nl2xbr($data) {
return (!empty($data)) ? str_replace("\n", "<br />\n", $data) : '';
}


HTH =)

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
http://www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
  Reply With Quote
3 2nd November 12:26
luna
External User
 
Posts: 1
Default replacing carriage returns with


thanks for the quick reply - appreciated,
i used $data = str_replace("\n", "<br />", $data) : ''; in the end as i was passing the
data to an odbc access database - the entry works well eg line1<br>line2<br>
works a treat!
  Reply With Quote
4 2nd November 12:26
ian.h [ds]
External User
 
Posts: 1
Default replacing carriage returns with


On Tue, 19 Aug 2003 15:10:06 +0100 in
<message-id:bhtaru$5s5$1@news6.svr.pol.co.uk>

No probs =)


Ahh makes sense. I normally include the \n after the <br /> in the
function so that on display in an HTML "view source" page, it looks
half-readable and "formatted" too.. hence it was added "by default" to
my function.

Glad all works =)

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
http://www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
  Reply With Quote
5 2nd November 12:26
andy hassall
External User
 
Posts: 1
Default replacing carriage returns with


nl2br outputs XHTML compliant <br /> tags.

http://uk2.php.net/nl2br

--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage ****ysis tool (http://www.andyhsoftware.co.uk/space)
  Reply With Quote
6 2nd November 12:26
ian.h [ds]
External User
 
Posts: 1
Default replacing carriage returns with


On Tue, 19 Aug 2003 19:36:39 +0100 in
<message-id:ggr4kvc17tm73mcj6jfavscr0b1c5ku6ja@4ax.com>


Oops.. I should have read more clearly; has been a while since I looked
up this function.

Thanks for the clarification.. useful to know =)

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
http://www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666