正则表达式将文本中的空格替换为
我有一个html代码。像这样:
<div>
(<- it is a tab) blaaaa ttoooo
<span id="span" class="class">Hiii Bye</span>
(<- these are 4 space character)
<span id="span" class="class">Welcome Back</span>
</div>
我想替换 >" "
,而不是任何制表符 (\t
)) code> 和 <
(表示空格不在 html 标记中)与
。 (使用 PHP 和 RegEX)
所以替换后,我的代码如下:
<div>
blaaaa ttoooo
<span id="span" class="class">Hiii Bye</span>
<- these are 4 space character
<span id="span" class="class">Welcome Back</span>
</div>
我怎样才能做到这一点?
非常感谢。 ...
I've a html code. like this:
<div>
(<- it is a tab) blaaaa ttoooo
<span id="span" class="class">Hiii Bye</span>
(<- these are 4 space character)
<span id="span" class="class">Welcome Back</span>
</div>
I want to replace any space(s) (only space: " "
, and not any tab (\t
)) between >
and <
(means the space(s) isn't in a html tag) with
. (with PHP and RegEX)
So after replacing, my code it it:
<div>
blaaaa ttoooo
<span id="span" class="class">Hiii Bye</span>
<- these are 4 space character
<span id="span" class="class">Welcome Back</span>
</div>
How can I do this??
Thank you very much. ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
丑陋,但它会起作用:
但不适用于最外层标签之外的空格。
Ugly, but it will work:
but not for spaces outside of the outermost tags.
不。请改用
whitespace: pre
CSS 声明。Don't. Use a
whitespace: pre
CSS declaration instead.