如何删除
(隐藏)和下面文本中的空格但是
<br>
标签我测试过:
trim($string)
=>没工作str_replace(' ', '', $string)
=>没工作我使用了一些正则表达式=>没有工作
<br>????? ????: ?????? ?? ???? ??? ????
Run Code Online (Sandbox Code Playgroud)更新:
谢谢
最终解决方案:
$string = htmlentities($string, null, 'utf-8');
$string = str_replace(" ", "", $string);
Run Code Online (Sandbox Code Playgroud)
小智 58
这个解决方案可行,我测试了它:
$string = htmlentities($content, null, 'utf-8');
$content = str_replace(" ", "", $string);
$content = html_entity_decode($content);
Run Code Online (Sandbox Code Playgroud)
Ben*_*rey 37
未经测试,但如果你使用类似的东西:
$string = preg_replace("/\s/",'',$string);
Run Code Online (Sandbox Code Playgroud)
这应该删除所有空格.
UPDATE
要删除所有空格和
引用,请使用以下内容:
$string = preg_replace("/\s| /",'',$string);
Run Code Online (Sandbox Code Playgroud)
更新2
试试这个:
$string = html_entity_decode($string);
$string = preg_replace("/\s/",'',$string);
echo $string;
Run Code Online (Sandbox Code Playgroud)
忘了说,重新转换html实体,所以在替换后添加:
htmlentities($string);
Run Code Online (Sandbox Code Playgroud)
小智 5
上述所有解决方案都有效,直到开始使用德语,其中有这样的字母:
\n\n\xc3\xa4 ä\n
Run Code Online (Sandbox Code Playgroud)\n\n和其他类似的。\n我使用以下代码:
\n\n$string = preg_replace ( "!\\s++!u", \' \', $string );\n
Run Code Online (Sandbox Code Playgroud)\n\n更多详细信息请参见:PCRE(3) 库函数手册
\n 归档时间: |
|
查看次数: |
75754 次 |
最近记录: |