note 24679 deleted from function.explode by aidan
| From: | aidan@php.net | Date: | Sun, 27 Jun 2004 14:32:47 +0000 |
| Subject: | note 24679 deleted from function.explode by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71933@lists.php.net to get a copy of this message | ||
Note Submitter:
----
explode() and implode() work appropriately with single-quoted glue strings:
// explode(';', 'a;b;c') is identical to
// explode(";", "a;b;c").
The difference is not in explode() itself, it's the semantic of quotes around string constants,
so:
// explode('\n', 'a\nb\nc')
// returns array([0] => "a", [1] => "nb", [2] => "nc"),
because the '\n' sequences in parameters means the sequence of a BACKSLASH and
'n', which is NOT interpreted as one newline character in single quoted strings, but as
two characters; here explode only uses the first BACKSLASH in the glue parameter and splits the
string by searching it in the second string parameter.
// explode('\n', 'a\nb\nc')
// returns array([0] => "a", [1] => "nb", [2] => "nc"),
because the glue parameter has TWO characters BACKSLASH and 'n', and explode only uses the
first character of the glue.
// explode("\n", 'a\nb\nc')
// returns array([0] => "a\\nb\\nc"),
because the second string parameter contains NO NEWLINE, but BACKSLASHES.
// explode('\n', "a\nb\nc")
// returns array([0] => "a\nb\nc"),
because the second string parameter contains NO BACKSLASH (the first character of the glue
parameter), but NEWLINES.