将PHP回显的输出限制为200个字符 [英] Limiting the output of PHP's echo to 200 characters

查看:71
本文介绍了将PHP回显的输出限制为200个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图将我的PHP echo限制为仅200个字符,然后再用"..."替换它们.

I'm trying to limit my PHP echo to only 200 characters and then if there are any more replace them with "...".

如何修改以下语句以允许这样做?

How could I modify the following statement to allow this?

<?php echo $row['style-info'] ?>

推荐答案

好,您可以创建一个自定义函数:

Well, you could make a custom function:

function custom_echo($x, $length)
{
  if(strlen($x)<=$length)
  {
    echo $x;
  }
  else
  {
    $y=substr($x,0,$length) . '...';
    echo $y;
  }
}

您可以这样使用它:

<?php custom_echo($row['style-info'], 200); ?>

这篇关于将PHP回显的输出限制为200个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆