• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

php strings

Because I have worked with C++ a few years ago I know that C++ and PHP have some string endings like \n and \r. Now I need them for a little project, but I don't know what they all do. Could anyone help me with that?
  • 2
1 Solution
this are escape characers. \n is for carrige return \r is a tabulator
Actually, \n is linefeed, \r is carriage return. On UNIX-like systems (e.g. Linux) only \n is needed for a CRLF, whereas on DOS/Windows both \r\n are required.

\t is a tab character.

In "double-quoted strings", you also need to escape certain other characters in order to print them:

\\ for a backslash
\$ for a dollar sign
\" for a double-quote

In 'single-quoted strings' you only need to escape a
single-quote itself - everything else is treated as a
normal character.

See http://www.php.net/manual/en/language.types.string.php for the relevant PHP manual page.
yes to linxit, except that "[on *nix] only \n [being linefeed] is needed for a CRLF" is a bit misleading as CRLF means CarriageReturn+LineFeed ;-)

the complete truth is that *nix systems are happy with lines ended by line feed (LF) whilst others (Mac included?) need CRLF
Yes, I didn't explain it as well as I could have. We could say that a linefeed implies a carriage return on *nix whereas it doesn't on DOS/Win (I don't know how Macs do it).

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now