CakeFest 2025 Madrid: The Official CakePHP Conference

Voting

: six plus two?
(Example: nine)

The Note You're Voting On

Steve
20 years ago
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.

<< Back to user notes page

To Top