gpt4 book ai didi

php - 如何去除 PHP 变量中的空格?

转载 作者:IT老高 更新时间:2023-10-28 11:56:02 28 4
gpt4 key购买 nike

我知道 comment PHP.net。我想有一个类似的工具,如 PHP 的 tr 这样我可以简单地运行

tr -d " " ""

我没有成功运行函数 php_strip_whitespace by

$tags_trimmed = php_strip_whitespace($tags);

我也没有成功运行正则表达式函数

$tags_trimmed = preg_replace(" ", "", $tags);

最佳答案

要去除任何空格,您可以使用正则表达式

$str=preg_replace('/\s+/', '', $str);

另见 this answer对于可以处理 UTF-8 字符串中的空格的东西。

关于php - 如何去除 PHP 变量中的空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1279774/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com