我正在从 MySQL 数据库中获取 $row['message']
并且我需要删除所有空格,例如 \n
\t
等等。
$row['message'] = "This is a Text \n and so on \t Text text.";
应格式化为:
$row['message'] = 'This is a Text and so on Text text.';
我试过了:
$ro = preg_replace('/\s\s+/', ' ',$row['message']);
echo $ro;
但它不会删除 \n
或 \t
,只是单个空格。谁能告诉我该怎么做?
原文由 creativz 发布,翻译遵循 CC BY-SA 4.0 许可协议
简化为一个功能:
基于丹尼尔奥尼尔的回答。