Connecting Tech Pros Worldwide Help | Site Map

Replace in PHP

  #1  
Old January 26th, 2006, 04:15 PM
John K
Guest
 
Posts: n/a
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!

  #2  
Old January 26th, 2006, 05:45 PM
Joe Molloy
Guest
 
Posts: n/a

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]


  #3  
Old January 26th, 2006, 05:45 PM
Michael Austin
Guest
 
Posts: n/a

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.
  #4  
Old January 26th, 2006, 06:25 PM
John K
Guest
 
Posts: n/a

re: Replace in PHP


Excellent! Works perfectly!!

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use fedex web service in php to calculate shipping fee supperham answers 3 July 11th, 2008 02:35 PM
Complex replace in php 4 Fabri answers 11 May 2nd, 2007 10:45 AM
string replace in php..? nirmalsingh answers 7 February 10th, 2007 02:46 PM
find and replace in every file under a root folder Cortes answers 2 July 17th, 2005 06:42 AM