php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #18705 More info in strstr()
Submitted: 2002-08-02 09:00 UTC Modified: 2003-01-20 13:59 UTC
From: ahristov at icygen dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.2.2 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ahristov at icygen dot com
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-02 11:43 UTC] 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-03 06:38 UTC] ahristov at icygen dot com
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.
 [2003-01-20 13:59 UTC] pollita@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 08 23:01:32 2025 UTC