Error[8]: Undefined offset: 16, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

php怎么去掉字符串两边的指定字符

php去掉字符串两边指定字符的方法:1、使用trim()函数,语法“trim(string,'指定字符')”;2、使用ltrim()和rtrim()函数,语法“rtrim(ltrim(string,'左侧指定字符'),'右侧指定字符')”。

本教程 *** 作环境:windows7系统、PHP7.1版、DELL G3电脑

php去掉字符串两边的指定字符

1、使用trim()函数

示例:去除字符串两边的逗号

<?php
header("Content-type:text/html;charset=utf-8"); 
$str = ',1,2,5,';
echo trim($str,',');
?>

trim() 函数移除字符串两侧的空白字符或其他预定义字符。

语法:

trim(string,charlist)
参数描述string必需。规定要检查的字符串。charlist可选。规定从字符串中删除哪些字符。如果省略该参数,则移除下列所有字符:

返回值:返回已修改的字符串。

<?php
header("Content-type:text/html;charset=utf-8"); 
$str = '-欢迎来到PHP中文网!';
echo rtrim(ltrim($str,'-'),'!');
?>

示例:

[+++]

推荐学习:《PHP视频教程》

以上就是php怎么去掉字符串两边的指定字符的详细内容,)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 29, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)

php怎么去掉字符串两边的指定字符_PHP_内存溢出

php怎么去掉字符串两边的指定字符

php怎么去掉字符串两边的指定字符,第1张

php怎么去掉字符串两边的指定字符

php去掉字符串两边指定字符的方法:1、使用trim()函数,语法“trim(string,'指定字符')”;2、使用ltrim()和rtrim()函数,语法“rtrim(ltrim(string,'左侧指定字符'),'右侧指定字符')”。

本教程 *** 作环境:windows7系统、PHP7.1版、DELL G3电脑

php去掉字符串两边的指定字符

1、使用trim()函数

示例:去除字符串两边的逗号

<?php
header("Content-type:text/html;charset=utf-8"); 
$str = ',1,2,5,';
echo trim($str,',');
?>

trim() 函数移除字符串两侧的空白字符或其他预定义字符。

语法:

trim(string,charlist)
参数描述string必需。规定要检查的字符串。charlist可选。规定从字符串中删除哪些字符。如果省略该参数,则移除下列所有字符:
  • "
  • "\t" - 制表符
  • " - NULL
  • "\n" - 换行
  • "\x0B" - 垂直制表符
  • "\r" - 回车
  • " " - 空格
  • 2、使用ltrim()和rtrim()函数

返回值:返回已修改的字符串。

<?php
header("Content-type:text/html;charset=utf-8"); 
$str = '-欢迎来到PHP中文网!';
echo rtrim(ltrim($str,'-'),'!');
?>

  • ltrim() - 移除字符串左侧的空白字符或其他预定义字符。

  • rtrim() - 移除字符串右侧的空白字符或其他预定义字符。

示例:

推荐学习:《PHP视频教程》

以上就是php怎么去掉字符串两边的指定字符的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/680423.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-20
下一篇 2022-04-20

发表评论

登录后才能评论

评论列表(0条)

保存