search for in the  
<Floating point numbersArrays>
Last updated: Thu, 19 May 2005

Strings

A string is series of characters. In PHP, a character is the same as a byte, that is, there are exactly 256 different characters possible. This also implies that PHP has no native support of Unicode. See utf8_encode() and utf8_decode() for some Unicode support.

Note: It is no problem for a string to become very large. There is no practical bound to the size of strings imposed by PHP, so there is no reason at all to worry about long strings.

Syntax

A string literal can be specified in three different ways.

Single quoted

The easiest way to specify a simple string is to enclose it in single quotes (the character ').

To specify a literal single quote, you will need to escape it with a backslash (\), like in many other languages. If a backslash needs to occur before a single quote or at the end of the string, you need to double it. Note that if you try to escape any other character, the backslash will also be printed! So usually there is no need to escape the backslash itself.

Note: In PHP 3, a warning will be issued at the E_NOTICE level when this happens.

Note: Unlike the two other syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

<?php
echo 'this is a simple string';

echo
'You can also have embedded newlines in
strings this way as it is
okay to do'
;

// Outputs: Arnold once said: "I'll be back"
echo 'Arnold once said: "I\'ll be back"';

// Outputs: You deleted C:\*.*?
echo 'You deleted C:\\*.*?';

// Outputs: You deleted C:\*.*?
echo 'You deleted C:\*.*?';

// Outputs: This will not expand: \n a newline
echo 'This will not expand: \n a newline';

// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';
?>

Double quoted

If the string is enclosed in double-quotes ("), PHP understands more escape sequences for special characters:

Table 11-1. Escaped characters

sequencemeaning
\nlinefeed (LF or 0x0A (10) in ASCII)
\rcarriage return (CR or 0x0D (13) in ASCII)
\thorizontal tab (HT or 0x09 (9) in ASCII)
\\backslash
\$dollar sign
\"double-quote
\[0-7]{1,3} the sequence of characters matching the regular expression is a character in octal notation
\x[0-9A-Fa-f]{1,2} the sequence of characters matching the regular expression is a character in hexadecimal notation

Again, if you try to escape any other character, the backslash will be printed too!

But the most important feature of double-quoted strings is the fact that variable names will be expanded. See string parsing for details.

Heredoc

Another way to delimit strings is by using heredoc syntax ("<<<"). One should provide an identifier after <<<, then the string, and then the same identifier to close the quotation.

The closing identifier must begin in the first column of the line. Also, the identifier used must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.

Warning

It is very important to note that the line with the closing identifier contains no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs after or before the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by your operating system. This is \r on Macintosh for example.

If this rule is broken and the closing identifier is not "clean" then it's not considered to be a closing identifier and PHP will continue looking for one. If in this case a proper closing identifier is not found then a parse error will result with the line number being at the end of the script.

It is not allowed to use heredoc syntax in initializing class members. Use other string syntaxes instead.

Example 11-3. Invalid example

<?php
class foo {
   public
$bar = <<<EOT
bar
EOT;
}
?>

Heredoc text behaves just like a double-quoted string, without the double-quotes. This means that you do not need to escape quotes in your here docs, but you can still use the escape codes listed above. Variables are expanded, but the same care must be taken when expressing complex variables inside a heredoc as with strings.

Example 11-4. Heredoc string quoting example

<?php
$str
= <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

/* More complex example, with variables. */
class foo
{
   var
$foo;
   var
$bar;

   function
foo()
   {
      
$this->foo = 'Foo';
      
$this->bar = array('Bar1', 'Bar2', 'Bar3');
   }
}

$foo = new foo();
$name = 'MyName';

echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some
{$foo->bar[1]}.
This should print a capital 'A':
\x41
EOT;
?>

Note: Heredoc support was added in PHP 4.

Variable parsing

When a string is specified in double quotes or with heredoc, variables are parsed within it.

There are two types of syntax: a simple one and a complex one. The simple syntax is the most common and convenient. It provides a way to parse a variable, an array value, or an object property.

The complex syntax was introduced in PHP 4, and can be recognised by the curly braces surrounding the expression.

Simple syntax

If a dollar sign ($) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces if you want to explicitly specify the end of the name.

<?php
$beer
= 'Heineken';
echo
"$beer's taste is great"; // works, "'" is an invalid character for varnames
echo "He drank some $beers"// won't work, 's' is a valid character for varnames
echo "He drank some ${beer}s"; // works
echo "He drank some {$beer}s"; // works
?>

Similarly, you can also have an array index or an object property parsed. With array indices, the closing square bracket (]) marks the end of the index. For object properties the same rules apply as to simple variables, though with object properties there doesn't exist a trick like the one with variables.

<?php
// These examples are specific to using arrays inside of strings.
// When outside of a string, always quote your array string keys
// and do not use {braces} when outside of strings either.

// Let's show all errors
error_reporting(E_ALL);

$fruits = array('strawberry' => 'red', 'banana' => 'yellow');

// Works but note that this works differently outside string-quotes
echo "A banana is $fruits[banana].";

// Works
echo "A banana is {$fruits['banana']}.";

// Works but PHP looks for a constant named banana first
// as described below.
echo "A banana is {$fruits[banana]}.";

// Won't work, use braces.  This results in a parse error.
echo "A banana is $fruits['banana'].";

// Works
echo "A banana is " . $fruits['banana'] . ".";

// Works
echo "This square is $square->width meters broad.";

// Won't work. For a solution, see the complex syntax.
echo "This square is $square->width00 centimeters broad.";
?>

For anything more complex, you should use the complex syntax.

Complex (curly) syntax

This isn't called complex because the syntax is complex, but because you can include complex expressions this way.

In fact, you can include any value that is in the namespace in strings with this syntax. You simply write the expression the same way as you would outside the string, and then include it in { and }. Since you can't escape '{', this syntax will only be recognised when the $ is immediately following the {. (Use "{\$" or "\{$" to get a literal "{$"). Some examples to make it clear:

<?php
// Let's show all errors
error_reporting(E_ALL);

$great = 'fantastic';

// Won't work, outputs: This is { fantastic}
echo "This is { $great}";

// Works, outputs: This is fantastic
echo "This is {$great}";
echo
"This is ${great}";

// Works
echo "This square is {$square->width}00 centimeters broad.";

// Works
echo "This works: {$arr[4][3]}";

// This is wrong for the same reason as $foo[bar] is wrong
// outside a string.  In other words, it will still work but
// because PHP first looks for a constant named foo, it will
// throw an error of level E_NOTICE (undefined constant).
echo "This is wrong: {$arr[foo][3]}";

// Works.  When using multi-dimensional arrays, always use
// braces around arrays when inside of strings
echo "This works: {$arr['foo'][3]}";

// Works.
echo "This works: " . $arr['foo'][3];

echo
"You can even write {$obj->values[3]->name}";

echo
"This is the value of the var named $name: {${$name}}";
?>

String access and modification by character

Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string in curly braces.

Note: For backwards compatibility, you can still use array-brackets for the same purpose. However, this syntax is deprecated as of PHP 4.

Example 11-5. Some string examples

<?php
// Get the first character of a string
$str = 'This is a test.';
$first = $str{0};

// Get the third character of a string
$third = $str{2};

// Get the last character of a string.
$str = 'This is still a test.';
$last = $str{strlen($str)-1};

// Modify the last character of a string
$str = 'Look at the sea';
$str{strlen($str)-1} = 'e';
        
?>

Useful functions and operators

Strings may be concatenated using the '.' (dot) operator. Note that the '+' (addition) operator will not work for this. Please see String operators for more information.

There are a lot of useful functions for string modification.

See the string functions section for general functions, the regular expression functions for advanced find&replacing (in two tastes: Perl and POSIX extended).

There are also functions for URL-strings, and functions to encrypt/decrypt strings (mcrypt and mhash).

Finally, if you still didn't find what you're looking for, see also the character type functions.

Converting to string

You can convert a value to a string using the (string) cast, or the strval() function. String conversion is automatically done in the scope of an expression for you where a string is needed. This happens when you use the echo() or print() functions, or when you compare a variable value to a string. Reading the manual sections on Types and Type Juggling will make the following clearer. See also settype().

A boolean TRUE value is converted to the string "1", the FALSE value is represented as "" (empty string). This way you can convert back and forth between boolean and string values.

An integer or a floating point number (float) is converted to a string representing the number with its digits (including the exponent part for floating point numbers).

Arrays are always converted to the string "Array", so you cannot dump out the contents of an array with echo() or print() to see what is inside them. To view one element, you'd do something like echo $arr['foo']. See below for tips on dumping/viewing the entire contents.

Objects are always converted to the string "Object". If you would like to print out the member variable values of an object for debugging reasons, read the paragraphs below. If you would like to find out the class name of which an object is an instance of, use get_class(). As of PHP 5, __toString() method is used if applicable.

Resources are always converted to strings with the structure "Resource id #1" where 1 is the unique number of the resource assigned by PHP during runtime. If you would like to get the type of the resource, use get_resource_type().

NULL is always converted to an empty string.

As you can see above, printing out the arrays, objects or resources does not provide you any useful information about the values themselves. Look at the functions print_r() and var_dump() for better ways to print out values for debugging.

You can also convert PHP values to strings to store them permanently. This method is called serialization, and can be done with the function serialize(). You can also serialize PHP values to XML structures, if you have WDDX support in your PHP setup.

String conversion to numbers

When a string is evaluated as a numeric value, the resulting value and type are determined as follows.

The string will evaluate as a float if it contains any of the characters '.', 'e', or 'E'. Otherwise, it will evaluate as an integer.

The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional exponent. The exponent is an 'e' or 'E' followed by one or more digits.

<?php
$foo
= 1 + "10.5";                // $foo is float (11.5)
$foo = 1 + "-1.3e3";              // $foo is float (-1299)
$foo = 1 + "bob-1.3e3";          // $foo is integer (1)
$foo = 1 + "bob3";                // $foo is integer (1)
$foo = 1 + "10 Small Pigs";      // $foo is integer (11)
$foo = 4 + "10.2 Little Piggies"; // $foo is float (14.2)
$foo = "10.0 pigs " + 1;          // $foo is float (11)
$foo = "10.0 pigs " + 1.0;        // $foo is float (11)   
?>

For more information on this conversion, see the Unix manual page for strtod(3).

If you would like to test any of the examples in this section, you can cut and paste the examples and insert the following line to see for yourself what's going on:

<?php
echo "\$foo==$foo; type is " . gettype ($foo) . "<br />\n";
?>

Do not expect to get the code of one character by converting it to integer (as you would do in C for example). Use the functions ord() and chr() to convert between charcodes and characters.



User Contributed Notes
Strings
shadda at gmail dot com
24-Jan-2005 07:39
It's fun to use heredoc syntax in conjunction with sprintf, and quite effective in my opinion.

sprintf(<<<EOS
The dog ran over the %s,
and landed on the %s
EOS
,'cat','floor');

Dunno if anyone else likes this method, but Its certainly usefull for constructing long verbose SQL statements.

Cheers.
lelon at lelon dot net
27-Oct-2004 03:01
You can use the complex syntax to put the value of both object properties AND object methods inside a string.  For example...
<?php
class Test {
   public
$one = 1;
   public function
two() {
       return
2;
   }
}
$test = new Test();
echo
"foo {$test->one} bar {$test->two()}";
?>
Will output "foo 1 bar 2".

However, you cannot do this for all values in your namespace.  Class constants and static properties/methods will not work because the complex syntax looks for the '$'.
<?php
class Test {
   const
ONE = 1;
}
echo
"foo {Test::ONE} bar";
?>
This will output "foo {Test::one} bar".  Constants and static properties require you to break up the string.
bishop
09-Sep-2004 06:47
Re: Jonathan Lozinski's note on vim syntax highlighting, we use EOHTML, EOSQL, and EOJAVASCRIPT quite frequently for HTML, SQL, and JavaScript, respectively.

eg:

<?php
$query
=<<<EOSQL
SELECT Foo.a,
       Foo.b,
       Bar.a
  FROM Foo
  LEFT
  JOIN Bar
     ON Foo.x=Bar.y
 WHERE Foo.b LIKE '%123%'
EOSQL;
?>

will be highlighted correctly for SQL under VIM.
Jonathan Lozinski
06-Aug-2004 03:03
A note on the heredoc stuff.

If you're editing with VI/VIM and possible other syntax highlighting editors, then using certain words is the way forward.  if you use <<<HTML for example, then the text will be hightlighted for HTML!!

I just found this out and used sed to alter all EOF to HTML.

JAVASCRIPT also works, and possibly others.  The only thing about <<<JAVASCRIPT is that you can't add the <script> tags..,  so use HTML instead, which will correctly highlight all JavaScript too..  There might be one for Text/css too?
skippy zuavra net
20-Jul-2004 11:55
The short version for the curly syntax:

1. $str{something} is the equivalent of $str[something]

2. Inside "" strings you can use any variable, no matter how complex the addressing mode (multiple index array, imbricated objects) by enclosing the variable in {}: "foo{$any_variable}bar".

To add to the confusion:

a) The two uses above have nothing in common, conceptually. For instance, #1 can use operations or functions as that something, #2 is restricted to just variables.

b) In #2, you can use either ${ or {$ to open the curly expression ie. "${var}" and "{$var}" are equivalent.
rtb27 at cam dot ac dot uk
30-Jun-2004 10:59
If you want side effects to occur during variable substituion inside strings, the "?" operator can help. For example:

<?php

$i
= 0;
echo <<<LONGSTRING

one
{${$i++ ? "i" : "i"}}
two
{${$i++ ? "i" : "i"}}
three
{${$i++ ? "i" : "i"}}

LONGSTRING;

?>

will print: "one 1 two 2 three 3"
www.feisar.de
28-Apr-2004 10:49
watch out when comparing strings that are numbers. this example:

<?php

$x1
= '111111111111111111';
$x2 = '111111111111111112';

echo (
$x1 == $x2) ? "true\n" : "false\n";

?>

will output "true", although the strings are different. With large integer-strings, it seems that PHP compares only the integer values, not the strings. Even strval() will not work here.

To be on the safe side, use:

$x1 === $x2
atnak at chejz dot com
11-Apr-2004 06:53
Here is a possible gotcha related to oddness involved with accessing strings by character past the end of the string:

$string = 'a';

var_dump($string{2});  // string(0) ""
var_dump($string{7});  // string(0) ""
$string{7} === '';  // TRUE

It appears that anything past the end of the string gives an empty string..  However, when E_NOTICE is on, the above examples will throw the message:

Notice:  Uninitialized string offset:  N in FILE on line LINE

This message cannot be specifically masked with @$string{7}, as is possible when $string itself is unset.

isset($string{7});  // FALSE
$string{7} === NULL;  // FALSE

Even though it seems like a not-NULL value of type string, it is still considered unset.
zefram at cesena dot net
30-Mar-2004 07:04
Make attention to string conversion!
Strings may evaluate to true but also to zero!!

<?
 $hello
='hi there';
 echo(
$hello?'true':'false');        //true
 
echo($hello==0?'true':'false');      //true!!!!!
 
echo($hello===0?'true':'false');    //false
?>
maka3d at yahoo dot com dot br
26-Feb-2004 01:46
Remember that even PHP is type less, some convertions like INTEGER to STRING is not done when using character direct access like string functions does.
<?php
$str
= '456';
echo
strlen($str); // strlen convert int to string automatically
echo $str{0}; // this works
$str = 456;
echo
$str{0}; // this NOT works
$str = (string)$str; // do type cast to string
echo $str{1}; // now it works
?>
gijs at dghostingworld dot com
23-Feb-2004 02:18
If you use the heredoc syntax and you want to insert an function that echo's something use the following escape sequence: {${header('This is text', 'color')}}

This will execute the function.

hope this helps somebody.

G
marcus at synchromedia dot co dot uk
25-Jan-2004 06:41
If you need to output a string that contains the 'end of php' sequence ?>, or perhaps you have trouble with your editor's syntax colouring because of it, for instance if you wish to do this:

<?php
print "<?xml version=\"1.0\"?>\n";
?>

you can instead use an encoded char to remove the confusion:

<?php
print "<?xml version=\"1.0\"\x3F>\n";
?>

Note that this notes page doesn't have a problem with this syntax!
dandrake
19-Jan-2004 06:41
By the way, the example with the "\n" sequence will insert a new line in the html code, while the output will be decided by the HTML syntax. That's why, if you use

<?
 
echo "Hello \n World";
?>

the browser will receive the HTML code on 2 lines
but his output on the page will be shown on one line only.
To diplay on 2 lines simply use:

<?
 
echo "Hello <br>World";
?>

like in HTML.
mina86 at tlen dot pl
25-Dec-2003 02:00
Re: reuterpl at wp dot pl
No, that's not true.. I mean not exactly true gowever I know what you meant but begginers may not know and feal confused..

<?php
$str
= "Hello \n World";

echo(
$str);
// Output:
//  Hello
//    World
// Browser renders it as:
//  Hello World

echo('<pre>' . $str . '</pre>');
// Output:
//  <pre>Hello
//    World</pre>
// Browser renders it as:
//  Hello
//  World

$str = nl2br($str);
echo(
$str);
// Output:
//  Hello <br /> World
// Browser renders it as:
//  Hello
//  World

echo('<pre>' . $str . '</pre>');
// Output:
//  <pre>Hello <br /> World</pre>
// Browser renders it as:
//  Hello
//
//    World
?>

Re: cs_1 at gmx dot de
I use only UNIX line ends an have no problems with heredoc syntax, so maybe your problem was with something else..
dev6 at es11 dot com
28-Aug-2003 03:42
In response to the most recent post, by Edwin:  Huh? 

First, $foo is not NULL terminated, it's newline terminated.  NULL and \n are not even remotely the same thing. 

Second, the example you posted works perfectly.  Both values get computed and printed as 3.0, not 2.0.
edwin at se-technology dot com
06-Jun-2003 05:58
This one took me a while to sort out:

$foo = "1.5\n";
$bar = "1.5";
printf ("%6.2f, %6.2f ", $foo*2, $bar*2);

>> 2.0, 3.0

So apparently string conversion is messed up by NULL, an obvious solution in case you happen to have a NULL terminated string is:

$foo = rtrim ($foo);
gmarik at hotbox dot ru
24-Apr-2003 02:57
This is how I did it, if tou need to cut big text blocks in easy to browse text blocks:

$str = "bla bla nla. asdfasd. fdsfd fafsasf. asasdwe fdscz asdvc. afasffas. afafs vcxrqw cvea.";

preg_match_all("/.{1500,}?\./s",$str,$out,PREG_PATTERN_ORDER);
list($out) = $out;

print_r($out);

And this is the dynamic menu to navigate between the blocks:

for ($i=0; $i<count($out); $i++) {
$pgnum = $i+1;
echo "<option value=$pgnum>$pgnum</option>";
}
philip at cornado dot com
11-Apr-2003 08:37
Note that in PHP versions 4.3.0 and 4.3.1, the following provides a bogus E_NOTICE (this is a known bug):

echo "$somearray['bar']";

This is accessing an array inside a string using a quoted key and no {braces}.  Reading the documention shows all the correct ways to do this but the above will output nothing on most systems (most have E_NOTICE off) so users may be confused.  In PHP 4.3.2, the above will again yield a parse error.
03-Mar-2003 01:04
Regarding "String access by character":

Apparently if you edit a specific character in a string, causing the string to be non-continuous, blank spaces will be added in the empty spots.

echo '<pre>';
$str = '0123';
echo "$str\n";
$str{4} = '4';
echo "$str\n";
$str{6} = '6';
echo "$str\n";

This will output:
0123
01234
01234 6
Notice the blank space where 5 should be.

(PHP 4.3.1)
cs_1 at gmx dot de
11-Feb-2003 03:57
Be sure to save your PHP files with CrLf line ends when using the heredoc syntax for a variable, e.g.:

$var1 = <<<EOT
sdsdsd
EOT;

didn't work on my linux system when using unix line ends...
Jeff at jsgennusa at yahoo dot com
24-Jan-2003 02:28
This is why this is right:

$beer = 'Heineken';
echo "$beer's taste is great"; // works, "'" is an invalid character for varnames
echo "He drank some $beers";  // won't work, 's' is a valid character for varnames
echo "He drank some ${beer}s"; // works

In all these examples, the php code is looking for the variable $beer. 
In the first one, it works because when it finds $beer's it actually finds $beer and stops at the '. 
In the second one, it doesn't work because there is no variable designated as $beers.
The third one works because the php code reads { and } as specifying what the actually variable is that it should be looking for.  The { and } allow you to add onto the variable.
jm at roth dot lu
18-Jan-2003 10:09
ERRATA?

Shouldn't this :

echo "$beer's taste is great"; // works, "'" is an invalid character for varnames
echo "He drank some $beers";  // , 's' is a valid character for varnames
echo "He drank some ${beer}s"; // works

be like that:

echo "$beer's taste is great"; // won't work, "'" is an invalid character for varnames
echo "He drank some $beers";  // works, 's' is a valid character for varnames
echo "He drank some ${beer}s"; // works
vallo at cs dot helsinki dot fi
03-Nov-2002 08:41
Even if the correct way to handle variables is determined from the context, some things just doesn't work without doing some preparation.

I spent several hours figuring out why I couldn't index a character out of a string after doing some math with it just before. The reason was that PHP thought the string was an integer!

$reference = $base + $userid;
.. looping commands ..
$chartohandle = $reference{$last_char - $i};

Above doesn't work. Reason: last operation with $reference is to store a product of an addition -> integer variable. $reference .=""; (string catenation) had to be added before I got it to work:

$reference = $base + $userid;
$reference .= "";
.. looping commands ..
$chartohandle = $reference{$last_char - $i};

Et voilá! Nice stream of single characters.
junkit at gmx dot net
15-Aug-2002 10:08
If you need to escape "$" to be escaped in the output, you need "\\\\$" - or maybe even more!

$ is a control character in Latex. If you want it to become \$ for further processing through Latex, it seems that there must be 4 (!) backslashes - so that in the end there is one left after processing the string twice. Once through str_replace and once through preg_replace!

Using 4.1.0 on Windows.
guidod at gmx dot de
23-Jul-2002 02:26
PHP's double-quoted strings are inherently ill-featured - they will be a problem especially with computed code like in /e-evals with preg_replace.

bash and perl follow the widely accepted rule that all backslashes will escape the nextfollowing char, and nonalpha-chars will always get printed there as themselves whereas (the unescaped chars might have special meaning in regex). Anyway, it is a great way to just escape all nonalpha chars that you uncertain about whether they have special meaning in some places, and ye'll be sure they will get printed literal.

Furthermore, note that \{ sequence is not mentioned in the  escape-char table! You'll get to know about it only "complex (curly) syntax". This can even more be a problem with evals, as they behave rather flaky like it _cannot_ be accomodated for computed code. Try all variants of `echo "hello \{\$world}"` removing one or more of the chars in the \{\$ part - have fun!
03-Jun-2002 05:58
//Some more useful examples (and some that are only interesting):
$foo = 1 + "010";
//$foo is 11, not 9 - i.e. PHP doesn't recognize 010 as octal.

$foo = 1 + "0x10";
//$foo is 17 - i.e. PHP DOES recognize 0x10 as hex for 16.

$foo = 1 + "\x10";
$bar = 1 + "\x35"; //0x35 is ASCII for '5'
//$foo is 1, but $bar is 6.

$foo = 1 + "0x\x41\x31"; //0x41 is ASCII 'A'; 0x31 is '1'
//$foo is 162: 1 + 0xA1 = 1 + 161.

/*NOTE: These examples were "discovered" using PHP4, Apache2,
Red Hat 7.2*/
hleu at tomorrow-ag dot de
17-Aug-2001 09:07
see 'String conversion':
'...Otherwise, the value will be 0 (zero).'

now look at this:
<?php  if (0=='yes') echo "no!!!"?>
yes, it really says "no!!!"
...just something to keep in mind...
philip at cornado dot com
10-Aug-2000 04:38
A nice "Introduction to PHP Strings" tutorial:
  http://www.zend.com/zend/tut/using-strings.php
mmeisinger at commdot dot com
01-Feb-2000 06:28
The new line is very similar to VBScript's "vbcrlf". The only place where you will see the new line is in the "Post-Parsed" Code. The '\n' can also be used to format Email's and Text Files that PHP is writting.
So in closing, use '<br>' to create a new line for your HTML Page and use '\n' to format the Code and Text Files

<Floating point numbersArrays>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 18:35:34 2005 EDT