468,315 Members | 1,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

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!

Jan 26 '06 #1
3 4449
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" <ki*****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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!

Jan 26 '06 #2
John K wrote:
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>")
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
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.
str_replace([old_string],[new_string],[text string])

where old_string and new_string can be an array of text.

Thanks for the help!


You're welcome.

Michael.
Jan 26 '06 #3
Excellent! Works perfectly!!

Jan 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Craig Keightley | last post: by
6 posts views Thread by JackpipE | last post: by
15 posts views Thread by =?Utf-8?B?TWlrZSAiWU9fQkVFIiBC?= | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.