note 39236 added to function.strstr
| From: | RomualdBrunet at rn2 dot php dot net | Date: | Wed, 21 Jan 2004 17:25:33 +0000 |
| Subject: | note 39236 added to function.strstr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63966@lists.php.net to get a copy of this message | ||
Regarding the note of the manual concerning the speed of strstr against strpos, for people who wants
to check a needle occurs within haystack, it apprears that strstr() is in facts faster than
strpos().
Example:
<?php
// [VERY] Quick email check:
if ( strstr("email@domain.tld", "@") ) {
// Ok
}
?>
is faster than
<?php
if ( strpos("email@domain.tld", "@") !== FALSE ) {
// Ok
}
Without using the true equality with !==, strpos() is faster. But then if the haystack starts with
needle the condition whould not be met.
----
Manual Page -- http://www.php.net/manual/en/function.strstr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39236
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39236&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39236&report=yes
Search -- http://master.php.net/manage/user-notes.php