note 21942 modified in split by torben
| From: | torben@php.net | Date: | Fri, 31 May 2002 17:10:13 +0000 |
| Subject: | note 21942 modified in split by torben | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-31300@lists.php.net to get a copy of this message | ||
[Ed. note: Close. The pipe *is* an operator in PHP, but
the reason this fails is because it's also an operator
in the regex syntax. The distinction here is important
since a PHP operator inside a string is just a character.]
The reason your code:
$line = "12|3|Fred";
list ($msgid, $msgref, $msgtopic)=split('|', $line);
didn't work is because the "|" symbol is an operator in PHP. If you want to use the
pipe symbol as a delimiter you must excape it with a back slash, "\|". You code should
look like this:
$line = "12|3|Fred";
list ($msgid, $msgref, $msgtopic)=split('\|', $line);
--was--
The reason your code:
$line = "12|3|Fred";
list ($msgid, $msgref, $msgtopic)=split('|', $line);
didn't work is because the "|" symbol is an operator in PHP. If you want to use the
pipe symbol as a delimiter you must excape it with a back slash, "\|". You code should
look like this:
$line = "12|3|Fred";
list ($msgid, $msgref, $msgtopic)=split('\|', $line);
http://www.php.net/manual/en/split.php