从String PHP删除前3个字符和后3个字符 [英] Delete first 3 characters and last 3 characters from String PHP

查看:453
本文介绍了从String PHP删除前3个字符和后3个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除字符串的前3个字母和字符串的后3个字母.我知道我可以使用substr()从某个字符开始,但是如果我需要剥离第一个字符和最后一个字符,我不确定是否可以实际使用它.有什么建议?

I need to delete the first 3 letters of a string and the last 3 letters of a string. I know I can use substr() to start at a certain character but if I need to strip both first and last characters i'm not sure if I can actually use this. Any suggestions?

推荐答案

将负值作为length参数(第3个参数)传递给

Pass a negative value as the length argument (the 3rd argument) to substr(), like:

$result = substr($string, 3, -3);

所以这个:

<?php
$string = "Sean Bright";
$string = substr($string, 3, -3);
echo $string;
?>

输出:

n Bri

这篇关于从String PHP删除前3个字符和后3个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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