从字符串中删除第一个和最后一个字符 [英] Remove first and last char from string

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

问题描述

我有这个:

$dataList = "*one*two*three*";
$list = explode("*", $dataList);
echo"<pre>";print_r($list);echo"</pre>";

输出:

> Array (
>     [0] => 
>     [1] => one
>     [2] => two
>     [3] => three
>     [4] =>  )

如何在爆炸前去掉字符串中的第一个和最后一个 *?

How do I strip the fist and last * in the string before exploding?

推荐答案

Using trim:

Using trim:

trim($dataList, '*');

这将删除字符串末尾和开头的所有 * 字符(即使有多个!).

This will remove all * characters (even if there are more than one!) from the end and the beginning of the string.

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

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