Connecting Tech Pros Worldwide Forums | Help | Site Map

Replace in PHP

John K
Guest
 
Posts: n/a
#1: Jan 26 '06
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!


Joe Molloy
Guest
 
Posts: n/a
#2: Jan 26 '06

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.

Joe

"John K" <kinane3@yahoo.com> wrote in message
news:1138291525.377909.143800@g43g2000cwa.googlegr oups.com...[color=blue]
> 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!
>[/color]


Michael Austin
Guest
 
Posts: n/a
#3: Jan 26 '06

re: Replace in PHP


John K wrote:[color=blue]
> 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>")[/color]

an example from the PHP manuals:

$text="this is my text string\r\n";
$text=str_replace("\r\n","<br>",$text);
or
$text=str_replace("\r\n","<br>",$_POST['myvariable']);
where:
"\r" = CR
"\n" = LF[color=blue]
>
> 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.[/color]

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

where old_string and new_string can be an array of text.
[color=blue]
>
> Thanks for the help!
>[/color]

You're welcome.

Michael.
John K
Guest
 
Posts: n/a
#4: Jan 26 '06

re: Replace in PHP


Excellent! Works perfectly!!

Closed Thread