Created
April 3, 2012 00:05
-
-
Save suzuki/2288154 to your computer and use it in GitHub Desktop.
Detect charset from MIME string
This file contains hidden or 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
/** | |
* Detect charset from MIME string | |
* | |
* @params string | |
* @return mixed found a charset string (upper case) or couldn't found false | |
*/ | |
public function getCharsetFromMimeString($mimeString) { | |
$mimeString = trim($mimeString); | |
if (preg_match('/^=\?([^?]+)\?(:?B|Q)\?[^?]+\?=$/', $mimeString, $matched)){ | |
return strtoupper($matched[1]); | |
} | |
return false; | |
} |
ツッコミありがとうございます! false にします。
実はソコのところを迷ってたのですが、とりあえず null にしてました。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実装されているクラスのスタイルにも影響するし、これで全然問題ないのですが、
couldn't foundならnullよりfalseを返すほうが明確に見つからなかった意思が伝わって良いと思います。