LoginSignup
0
0

More than 3 years have passed since last update.

(めも)PHPで文字数制限をかけて出力する。

Posted at

echo substr('mojiretsu' , 始点 ,終点);

例:文字列がmojiretsuの場合に2文字目から4文字目までを出力する。
$str = 'mojiretsu'
echo substr($str ,1 , 4);

oji

mb_substr()

*substr()との違い。

substr():バイト数でカウント。半角1文字で1バイト、全角2文字で2バイト。
mb_substr():mbはマルチバイトの意。文字数でカウント、半角でも全角でも1文字。

なので日本語の文字列を使うならmb_substr()の方が楽。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0