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.
发表评论