Created
March 18, 2016 09:15
-
-
Save anon5r/8af67f02adaad0ffbbca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 前方一致 | |
* $haystackが$needleから始まるか判定します。 | |
* @param string $haystack | |
* @param string $needle | |
* @return boolean | |
*/ | |
function startsWith($haystack, $needle) | |
{ | |
return strpos($haystack, $needle, 0) === 0; | |
} | |
/** | |
* 後方一致 | |
* $haystackが$needleで終わるか判定します。 | |
* @param string $haystack | |
* @param string $needle | |
* @return boolean | |
*/ | |
function endsWith($haystack, $needle) | |
{ | |
$length = (strlen($haystack) - strlen($needle)); | |
// 文字列長が足りていない場合はFALSEを返します。 | |
if($length < 0) return FALSE; | |
return strpos($haystack, $needle, $length) !== FALSE; | |
} | |
/** | |
* 部分一致 | |
* $haystackの中に$needleが含まれているか判定します。 | |
* @param string $haystack | |
* @param string $needle | |
* @return boolean | |
*/ | |
function matchesIn($haystack, $needle) | |
{ | |
return strpos($haystack, $needle) !== FALSE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment