note 51209 modified in function.preg-split by danbrown

From: Date: Wed, 27 May 2009 13:50:22 +0000
Subject: note 51209 modified in function.preg-split by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156070@lists.php.net to get a copy of this message
preg_split() behaves differently from perl's split() if the string ends with a delimiter. This perl snippet will print 5: my @a = split(/ /, "a b c d e "); print scalar @a; The corresponding php code prints 6: <?php print count(preg_split("/ /", "a b c d e ")); ?> This is not necessarily a bug (nowhere does the documentation say that preg_split() behaves the same as perl's split()) but it might surprise perl programmers. --was-- preg_split() behaves differently from perl's split() if the string ends with a delimiter. This perl snippet will print 5: my @a = split(/ /, "a b c d e "); print scalar @a; The corresponding php code prints 6: print count(preg_split("/ /", "a b c d e ")); This is not necessarily a bug (nowhere does the documentation say that preg_split() behaves the same as perl's split()) but it might surprise perl programmers. http://php.net/manual/en/function.preg-split.php

« previous php.notes (#156070) next »