|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-08-02 09:00 UTC] ahristov at icygen dot com
Is it possible more information to be added to the docs of strstr() that it is better to look if there is needle in a haystack by using strpos() - in bold. Even small example. Regards, Andrey Hristov PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 16:00:01 2025 UTC |
Attention : Keep in mind that when you want whether there is substring into string it is better to use strpos() than to use strstr(). Most times users has problems to differentiate the cases where the substring is found at position 0 and in the case where it is not found. Example 2: $needle = "I love"; $haystack = "I love PHP!"; //using strstr() - bad - exhaust of memory and cpu if (strstr($haystack, $needle)){ // found } //using strpos() - good no exhaust of memory if (strpos($haystack, $needle) === TRUE){ // found } -=-=-=-=-= End of example.