LoginSignup
0
0

More than 1 year has passed since last update.

PHPで10文字以上の文章なら...をにする

Posted at

PHPで10文字以上の文章なら...をにする方法


//整形したい文字列
 $textLimits = $val ["TITLE"];
//文字数の上限
$limit = 10;

// 文字数10以上ならば、...に変換 
if(mb_strlen($textLimits) > $limit) { 
  $title = mb_substr($textLimits,0,$limit);
  echo $title. "..." ."</a>" ;
} else {
  echo $textLimits. "</a>";
}


//整形したい文字列
$textLimits = $val ["TITLE"];
//文字幅の上限
$limit = 10;

// 文字幅が10以上ならば、...に変換 半角が1 全角が2
if(mb_strwidth($textLimits) > $limit) {
// 文字列を文字幅上限に丸める
$title = mb_strimwidth($textLimits,0,$limit);
  echo $title. "..." ."</a>" ;
} else {
  echo $textLimits. "</a>";
}
0
0
2

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