php去掉字符串里空格的方法有哪些
php去掉字符串中的空格的方法有两种:1、定义变量$str,用于保存要更改的字符串,使用"str_replace()"函数,用一个空字符串替换所有空格,语法为"str_replace(' ', '', $str);2、"preg_replace()"函数,使用正则匹配,语法为"preg_replace('/s+/', '', $str)"。
本教程操作系统:Windows10系统、php8.1.3版本、Dell G3电脑。
php去掉字符串中的空格的方法有两种:
1、使用 str_replace()
$str = "This is a string with spaces."; $new_str = str_replace(' ', '', $str); echo $new_str; // Thisisastringwithspaces.
1、本站目前拥有近 1000+ 精品收费资源,现在加入VIP会员即可全部下载。
2、本资源部分来源其他付费资源平台或互联网收集,如有侵权请联系及时处理。
SEA模板网 » php去掉字符串里空格的方法有哪些
2、本资源部分来源其他付费资源平台或互联网收集,如有侵权请联系及时处理。
SEA模板网 » php去掉字符串里空格的方法有哪些
发表评论