phpで文字列から最初の5文字を取得する方法
$myStr = "HelloWordl";
結果は次のようになります。
$result = "Hello";
シングルバイト文字列](http://en.wikipedia.org/wiki/Single-byte_encoding) (US-ASCII, ISO 8859ファミリーなど)にはsubstr
を,マルチバイト文字列 (UTF-8, UTF-16など)にはmb_substr
を使用してください。
// singlebyte strings
$result = substr($myStr, 0, 5);
// multibyte strings
$result = mb_substr($myStr, 0, 5);