Strings

clookid

203.***.***.***
1,200 days ago

Strings

Strings
Strings are text, pure and simple. There's two ways of storing strings, inside single quotes and double-quotes. Using "double-quotes" allows you to use special characters like \n for a newline. The backslash character marks the next character as special, though the only characters you can backslash in 'single-quoted' strings are \' (a single quote) and \\ (a backslash).

Some other special characters (for double-quoted strings)

\t


TAB

\n


newline

\r


carriage-return. In DOS text-files, a new line is \r\n, though in practice in Windows you can get away with UNIX format, which is just \n

\$


$

\'


'

\"


"

The most important difference between single and double-quoted strings is that double-quoted strings can contain variable names:

PHP code:

$foo = 'This doesn\'t work'; // Oh yes it does!
$foo = "Matt's second line also works";

$age = 18;
echo 'Bob is $age'; // prints "Bob is $age"
echo "Bob is $age"; // prints "Bob is 18"



Check out the manual for more string stuff -- this is generally enough to get along with in daily use.