Browse - Programming Tips - PHP: startsWith() and endsWith()

Date: 2018sep27
Language: php

Q.  PHP: startsWith() and endsWith()

A.	

function startsWith($haystack, $needle) { $length = strlen($needle); return substr($haystack, 0, $length) === $needle; } function endsWith($haystack, $needle) { $length = strlen($needle); if ($length == 0) return true; return substr($haystack, -$length) === $needle; }