Edit report at https://bugs.php.net/bug.php?id=36944&edit=1
ID: 36944 Patch added by: larue...@php.net Reported by: ms419 at freezone dot co dot uk Summary: strncmp & negative len Status: Open Type: Feature/Change Request Package: Strings related Operating System: Debian PHP Version: 5.2.6 Block user comment: N Private report: N New Comment: The following patch has been added/updated: Patch Name: bug36944.phpt Revision: 1311594024 URL: https://bugs.php.net/patch-display.php?bug=36944&patch=bug36944.phpt&revision=1311594024 Previous Comments: ------------------------------------------------------------------------ [2011-07-25 11:37:53] larue...@php.net The following patch has been added/updated: Patch Name: php-5-3-strn-case-cmp-supporting-negative-length Revision: 1311593873 URL: https://bugs.php.net/patch-display.php?bug=36944&patch=php-5-3-strn-case-cmp-supporting-negative-length&revision=1311593873 ------------------------------------------------------------------------ [2011-07-25 11:06:44] larue...@php.net The following patch has been added/updated: Patch Name: php-5-3-strncasecmp-supporting-negative-length Revision: 1311592004 URL: https://bugs.php.net/patch-display.php?bug=36944&patch=php-5-3-strncasecmp-supporting-negative-length&revision=1311592004 ------------------------------------------------------------------------ [2008-11-25 18:45:46] ms419 at freezone dot co dot uk I wish to change this bug report to a feature request. I frequently need to check if a string begins or ends with another string. To check if a string begins with another string, I often use strncmp(): ket% php -r 'var_dump(strncmp("HTTP_ACCEPT", "HTTP_", 5));' int(0) ket% - but strncmp() is currently not able to check if a string ends with another string: ket% php -r 'var_dump(strncmp("foo_wrapper", "_wrapper", -8));' Warning: Length must be greater than or equal to 0 in Command line code on line 1 Call Stack: 0.0002 62840 1. {main}() Command line code:0 0.0002 62952 2. strncmp() Command line code:1 bool(false) ket% I wish strncmp() were able to check if a string ends with another string. ------------------------------------------------------------------------ [2006-04-05 11:37:45] tony2...@php.net This bug has been fixed in CVS. 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/. Thank you for the report, and for helping us make PHP better. Negative string length is not allowed in this function. I just committed the patch, from now you'll get an error and FALSE in this case. ------------------------------------------------------------------------ [2006-04-02 00:33:02] ms419 at freezone dot co dot uk Description: ------------ strncmp returns incorrect result given negative len - fis% php <?php var_dump(strncmp('foo_wrapper', '_wrapper', -8)); ?> int(7) fis% expected - int(0) returned - int(7) Thanks - Jack ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=36944&edit=1