在php中,如何从末尾开始按x个字符截断字符串? [英] in php, how do i truncate a string by x characters starting from the end?

查看:33
本文介绍了在php中,如何从末尾开始按x个字符截断字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 120 个字符的字符串截断为 100 个字符,但从字符串末尾开始计算长度?以便从字符串的开头而不是结尾删除 20 个字符?

How do I truncate a string thats 120 characters to 100 characters but have the count of the length start from the end of the string? So that the 20 characters are removed from the beginning of the string rather than the end?

推荐答案

$newString = substr($oldString, -100)将返回字符串的最后 100 个字符(如果字符串较短,则返回 false).

$newString = substr($oldString, -100) will return the last 100 characters of a string (or false if the string is shorter).

这篇关于在php中,如何从末尾开始按x个字符截断字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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