Replace in PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John K

    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(rsWhate ver("fld_whatev er_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

    #2
    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.goo glegroups.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(rsWhate ver("fld_whatev er_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]


    Comment

    • Michael Austin

      #3
      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(rsWhate ver("fld_whatev er_field"), vbCrLf, "<p>")[/color]

      an example from the PHP manuals:

      $text="this is my text string\r\n";
      $text=str_repla ce("\r\n","<br> ",$text);
      or
      $text=str_repla ce("\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.

      Comment

      • John K

        #4
        Re: Replace in PHP

        Excellent! Works perfectly!!

        Comment

        Working...