Connecting Tech Pros Worldwide Help | Site Map

Replace in PHP

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 26th, 2006, 03:15 PM
John K
Guest
 
Posts: n/a
Default Replace in PHP

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, 04:45 PM
Joe Molloy
Guest
 
Posts: n/a
Default 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, 04:45 PM
Michael Austin
Guest
 
Posts: n/a
Default 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, 05:25 PM
John K
Guest
 
Posts: n/a
Default Re: Replace in PHP

Excellent! Works perfectly!!

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.