A while ago I've had a discussion about the optimal way to determine a string length in PHP. The obvious way is to use strlen()
However to check the length of a minimal requirement it's actually not that optimal to use strlen. The following is actually much faster (roughly 5 times)
$str =
'This is a string';
if (isset($str[9])) { echo 'The input is longer or equal then 10 characters.';
} else { echo 'The input is less then 10 characters long.';
} And one other benefit is the fact that if the variable doesn't exists the isset() is still valid, while a strlen wouldn't be.
if (strlen($fubar) >=
10) { // Will throw E_NOTICE warning, since $fubar is not set. echo 'The input is longer or equal then 10 characters.';
} else { echo 'The input is less then 10 characters long.';
} On large pieces of code isset() is still faster but you notice that strlen() is definitely more optimized for it, since the speed doesn't differ much on large chunks of text. So for small validation checks I suggest writing your own little strlen checker of you want to gain a incredible speed difference of around 0.0004 seconds...
Apparently the sarcasm of this blog is failing for many readers, so I added this disclaimer: IT IS SARCASM, USE STRLEN.