【问题标题】:Correct PHP syntax to truncate in PHP line更正 PHP 语法以在 PHP 行中截断
【发布时间】:2017-09-13 02:44:16
【问题描述】:
$modelProfileURL = $site_url.'profile/model/2/'.$rs_model[$i]['iModelId'].'/'.replace_content($rs_model[$i]['vFirstName']).'_'.replace_content($rs_model[$i]['vLastName']);

我需要将名字和姓氏截断到最大值。 25 个字符。但我找不到编辑上面列出的代码的正确方法。例如,不是名称(例如:Mark Walker Smith Lewis Junior),而是 Mark Walker Smith Lewis J。这是设计目的所必需的。有人可以帮忙吗?

【问题讨论】:

标签: php truncate


【解决方案1】:

$modelProfileURL = $site_url.'profile/model/2/'.$rs_model[$i]['iModelId'].'/'.replace_content(substr($rs_model[$i]['vFirstName'],0,25)).'_'.replace_content(substr($rs_model[$i]['vLastName'],0,25));

【讨论】:

  • 感谢您的帮助。但这并没有限制名称中的字符数。
  • 你一定是做错了什么,因为substr() 在我描述的使用时肯定会限制字符串长度。能否举例说明这行执行后$modelProfileURL的内容?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-05
  • 1970-01-01
  • 1970-01-01
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多