如何使用php从字符串中获取前5个字符$myStr = "HelloWordl";结果应该是这样的$result = "Hello";
3 回答

米脂
TA贡献1836条经验 获得超3个赞
对于单字节字符串(例如US-ASCII,ISO 8859系列等),请使用substr;对于多字节字符串(例如UTF-8,UTF-16等),请使用mb_substr:
// singlebyte strings
$result = substr($myStr, 0, 5);
// multibyte strings
$result = mb_substr($myStr, 0, 5);

慕尼黑8549860
TA贡献1818条经验 获得超11个赞
您可以使用如下substr功能:
echo substr($myStr, 0, 5);
的第二个参数substr是从什么位置开始的,第三个参数是要返回多少个字符。
- 3 回答
- 0 关注
- 763 浏览
添加回答
举报
0/150
提交
取消