Replace in PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm new to PHP and come from and ASP background...

I want to replace line feeds in user submited textareas with <br> or
<p> or <div>.  In ASP I do this to replace carriage return/line feeds
with <p> in a record of a recordset...

Replace(rsWhatever("fld_whatever_field"), vbCrLf, "<p>")

I don't know how to accomplish this in PHP.  I know I have to use
str_replace() but I'm confused by the syntax.  

Thanks for the help!

Re: Replace in PHP

check out the nl2br function which replaces linefeed characters with  
linebreak tags or the str_replace function which works like the replace  
function in VB.


Quoted text here. Click to load it

Re: Replace in PHP

John K wrote:
Quoted text here. Click to load it

an example from the PHP manuals:

    $text="this is my text string\r\n";    
"\r" = CR
"\n" = LF
Quoted text here. Click to load it

str_replace([old_string],[new_string],[text string])

    where old_string and new_string can be an array of text.

Quoted text here. Click to load it

You're welcome.


Re: Replace in PHP

Excellent!  Works perfectly!!

Site Timeline