Which of the following code snippets would give two functions that would take a string and return, if it starts or ends with the specified character/string?
For example: $str='{apples}'; echo startsWith($str,'|'); //Returns true echo endsWith($str,'}'); //Returns true
Correct Answer:
function startsWith($haystack, $needle) { return !strncmp($haystack, $needle, strlen($needle)); } function endsWith($haystack, $needle) { $length = strlen($needle); if ($length == 0) { return true; } return (substr($haystack, -$length) === $needle); }
Explanation:
Note: This Question is unanswered, help us to find answer for this one
More PHP MCQ Questions