note 24679 added to function.explode

From: Date: Sun, 25 Aug 2002 16:14:41 +0000
Subject: note 24679 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-35594@lists.php.net to get a copy of this message
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. -- http://www.php.net/manual/en/function.explode.php http://master.php.net/manage/user-notes.php?action=edit+24679 http://master.php.net/manage/user-notes.php?action=delete+24679 http://master.php.net/manage/user-notes.php?action=reject+24679

« previous php.notes (#35594) next »