从String PHP中删除第一个字符和最后一个字符 [英] Delete first character and last character from String PHP

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

问题描述

我需要删除字符串的前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 ),如:

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

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

因此:

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

输出:

n Bri

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

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