SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    220
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question what do these mean '\n' '\r' '\t' ??

    as far as i know '\n' is equivalent to hitting return key(the "Enter" key of the keyboard) when typing inside <textarea></textarea>

    so without using a rich text editor like FCK, i need to parse '\n' like this
    PHP Code:
    $str str_replace("\n""<br>"$str); 
    how about '\t' and '\r', what do they mean? I mean what keys in the keyboard do they associated with??

    '\t' == hitting space bar? Tab key?

    sorry if this is a dumb question.


  2. #2
    SitePoint Member
    Join Date
    Jun 2007
    Location
    Gold Coast, Australia
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Leelong

    \t represents a tab
    \n represents a new line
    \r represents a carriage return

    Hope that clears it up for you!

  3. #3
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    220
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Vinno View Post
    Hi Leelong

    \t represents a tab
    \n represents a new line
    \r represents a carriage return

    Hope that clears it up for you!
    thank you very much!

    but i need to know the associated keys in the keyboard like '\n' == hitting Enter-key

    is my question not logic?

    '\t' == hitting the "Tab" key on the left of the keyboad??

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    "\r\n" = Enter
    "\r" = Enter
    "\n" = Enter

    (Depending on your OS)

    "\t" = Tab key

    Beware - in single quotes they are parsed as literal: "\n" -> newline, '\n' -> \n
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    220
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Talking

    ok...then let's look here

    $str = $_POST['Text_From_Textarea'];

    $str = strtr($str, array("\r" => ""));
    $str = str_replace("\n", "<br>", $str);
    $str = str_replace("\t", " ", $str);

    1st i remove all "\r" and then parse "\n" to <br>, but not sure if the last line is correct?? --> $str = str_replace("\t", " ", $str);


  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Take a look at nl2br as well.

  7. #7
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    220
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thank you all!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •