Newline problem "\n"

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

    #1

    Newline problem "\n"

    I'm having a problem getting rid of newlines.

    say I have this situation:

    $cat = "A nice\n cat";

    The "\n" is an escape character which creates a newline right there.

    Now, how would I get rid of the newline in that string?

    How would I then make that string: "A nice cat" ? without the newline
    being there?

    Also, another question.

    If I have a string, let's say: "The man\nwent to the\tdairy\ryes terday"
    Does anybody know of a function or of a way to display or find out the
    escaped characters in the string? Something that would point out which
    escaped characters were in the string?

    The reason that I am asking is because I put a form on a web page and I
    want to find out what escaped characters are in the resulting $_POST
    variable for one of the fields, for a javascript reason.

    Any help is much appreciated.

    Nick

  • Chris Hope

    #2
    Re: Newline problem "\n&quo t;

    mudge wrote:
    [color=blue]
    > I'm having a problem getting rid of newlines.
    >
    > say I have this situation:
    >
    > $cat = "A nice\n cat";
    >
    > The "\n" is an escape character which creates a newline right there.
    >
    > Now, how would I get rid of the newline in that string?
    >
    > How would I then make that string: "A nice cat" ? without the newline
    > being there?[/color]

    $cat = str_replace("\n ", "", $cat);
    [color=blue]
    > Also, another question.
    >
    > If I have a string, let's say: "The man\nwent to
    > the\tdairy\ryes terday" Does anybody know of a function or of a way to
    > display or find out the escaped characters in the string? Something
    > that would point out which escaped characters were in the string?
    >
    > The reason that I am asking is because I put a form on a web page and
    > I want to find out what escaped characters are in the resulting $_POST
    > variable for one of the fields, for a javascript reason.[/color]

    How about strpos($cat, "\n");

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    • mudge

      #3
      Re: Newline problem "\n&quo t;

      I can't beleive it. I figured it out.

      You see, when you fill in a field in a form and it gets past off to a
      $_POST in a php script, both "/n" and "/r" get attatched to each line
      break.

      The reason I couldn't get rid of the line breaks, was because I was
      only replacing "/n" when I also needed to replace "/r" as well.

      Thanks

      Comment

      • Jerry Sievers

        #4
        Re: Newline problem "\n&quo t;

        "mudge" <mudgen@gmail.c om> writes:
        [color=blue]
        > I can't beleive it. I figured it out.
        >
        > You see, when you fill in a field in a form and it gets past off to a
        > $_POST in a php script, both "/n" and "/r" get attatched to each line
        > break.
        >
        > The reason I couldn't get rid of the line breaks, was because I was
        > only replacing "/n" when I also needed to replace "/r" as well.[/color]

        Be careful. this may depend on what OS platform your client is on.
        All three of Linux, Mac, Windows use differing line termination.

        If memory serves; \n, \r\n, \n\r (respectively)

        If in the HTTP protocol spec it's required for any client to send \r\n
        for EOL, then you may disregard my advice.

        HTH
        [color=blue]
        >
        > Thanks
        >[/color]

        --
        -------------------------------------------------------------------------------
        Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
        305 321-1144 (mobile http://www.JerrySievers.com/

        Comment

        Working...