<?php
//分别用substr、strpos、substr_compare
//编写start_with、end_with函数
function start1($haystack, $needle) {
return substr($haystack, 0, mb_strlen($needle)) === $needle;
}
function start2($haystack, $needle) {
return strpos($haystack, $needle) === 0;
}
function start3($haystack, $needle) {
return substr_compare($haystack, $needle, 0, mb_strlen($needle)) === 0;
}
function end1($haystack, $needle) {
return substr($haystack, -mb_strlen($needle)) === $needle;
}
function end2($haystack, $needle) {
return strpos($haystack, $needle) === (mb_strlen($haystack) - mb_strlen($needle));
}
function end3($haystack, $needle) {
return substr_compare($haystack, $needle, -mb_strlen($needle)) === 0;
}
网友评论