ID: 36944 User updated by: ms419 at freezone dot co dot uk Reported By: ms419 at freezone dot co dot uk -Status: Closed +Status: Open -Bug Type: Strings related +Bug Type: Feature/Change Request Operating System: Debian -PHP Version: 4.4.2 +PHP Version: 5.2.6 New Comment:
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. Previous Comments: ------------------------------------------------------------------------ [2006-04-05 11:37:45] [EMAIL PROTECTED] 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 http://bugs.php.net/?id=36944&edit=1