note 126796 added to function.str-ends-with

From: Date: Sat, 22 Jan 2022 21:17:59 +0000
Subject: note 126796 added to function.str-ends-with
Groups: php.notes 
Request: Send a blank email to php-notes+get-217537@lists.php.net to get a copy of this message
Wordpress 5.9 RC3 does it this way: <?php if ( ! function_exists( 'str_ends_with' ) ) { function str_ends_with( $haystack, $needle ) { if ( '' === $haystack && '' !== $needle ) { return false; } $len = strlen( $needle ); return 0 === substr_compare( $haystack, $needle, -$len, $len ); } } ?> I suppose the compiler optimizes for the fact that substr_compare() is only being used for equality, not comparison ( <0, >0 ). ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 72.218.112.65) ---- Manual Page -- https://php.net/manual/en/function.str-ends-with.php Edit -- https://main.php.net/note/edit/126796 Del: integrated -- https://main.php.net/note/delete/126796/integrated Del: useless -- https://main.php.net/note/delete/126796/useless Del: bad code -- https://main.php.net/note/delete/126796/bad+code Del: spam -- https://main.php.net/note/delete/126796/spam Del: non-english -- https://main.php.net/note/delete/126796/non-english Del: in docs -- https://main.php.net/note/delete/126796/in+docs Del: other reasons-- https://main.php.net/note/delete/126796 Reject -- https://main.php.net/note/reject/126796 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217537) next »