Created
June 17, 2020 00:18
-
-
Save oppara/05566ec197ab0c0ec5d50d4c59f9ce79 to your computer and use it in GitHub Desktop.
trim
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 | |
/** | |
* trim(全角スペース含む)し、改行を取り除く | |
* | |
* @param string $str | |
* @return string | |
*/ | |
function trim(string $str): string | |
{ | |
$str = str_replace(["\r\n", "\r", "\n"], '', $str); | |
return preg_replace('/\A[\p{C}\p{Z}]++|[\p{C}\p{Z}]++\z/u', '', $str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment