从字符串中删除第一个和最后一个字符
我有这个:
$dataList = "*one*two*three*";
$list = explode("*", $dataList);
echo"<pre>";print_r($list);echo"</pre>";
which 输出:
> Array (
> [0] =>
> [1] => one
> [2] => two
> [3] => three
> [4] => )
如何在爆炸之前剥离字符串中的第一个和最后一个 *?
I have this:
$dataList = "*one*two*three*";
$list = explode("*", $dataList);
echo"<pre>";print_r($list);echo"</pre>";
which outputs:
> Array (
> [0] =>
> [1] => one
> [2] => two
> [3] => three
> [4] => )
How do I strip the fist and last * in the string before exploding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用
trim
:这将删除所有
*
字符(甚至如果有多个!)从字符串的末尾和开头。Using
trim
:This will remove all
*
characters (even if there are more than one!) from the end and the beginning of the string.其他一些可能性:
使用 substr:
您还可以选择不从字符串中删除 * ,而是删除空数组值,这些值始终是第一个和最后一个元素。
使用数组函数 array_pop() 和 array_shift():
Some other possibilities:
Using substr:
You can also choose to not remove the * from the string but rather remove the empty array values which will always be the first and last element.
Using array functions array_pop() and array_shift():
$string = substr($dataList, 1, -1);
去掉php中字符串的第一个和最后一个字符
$string = substr($dataList, 1, -1);
Remove the first and the last character of the string in php
希望这能解决你的问题
hope this solve your problem