#18705 [Fbk->Opn]: More info in strstr()

From: Date: Sat, 03 Aug 2002 10:38:51 +0000
Subject: #18705 [Fbk->Opn]: More info in strstr()
References: 1  Groups: php.bugs php.doc 
Request: Send a blank email to php-bugs+get-15907@lists.php.net to get a copy of this message
ID: 18705 User updated by: ahristov@icygen.com Reported By: ahristov@icygen.com -Status: Feedback +Status: Open Bug Type: Documentation problem Operating System: All PHP Version: 4.2.2 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2002-08-02 11:43:56] kalowsky@php.net Feel free to write the part you would like to see, submit it to this bug, and it will hopefully (probably) be added to the documentation. ------------------------------------------------------------------------ [2002-08-02 09:00:23] ahristov@icygen.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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=18705&edit=1

« previous php.bugs (#15907) next »