【发布时间】:2013-11-21 04:22:41
【问题描述】:
CKEditor 正在向我的数据库中输入的内容添加新行,这很好,只是需要将此数据作为单行 html 呈现到 javascript。
在我的 PHP 中有:
$tmpmaptext = $map['maptext'][$this->config->get('config_language_id')];
$tmpmaptext = html_entity_decode($tmpmaptext, ENT_QUOTES, 'UTF-8');
$tmpmaptext = str_replace(array('\r\n', '\n', '\r', '\t'), '', $tmpmaptext);
$tmpmaptext = str_replace(PHP_EOL, '', $tmpmaptext);
这几乎是我能找到的关于如何删除新行的所有内容,但我仍然在页面中找到了这个:
var infowindow01 = new google.maps.InfoWindow({
content: '<div><h2>Title</h2>
<p>Address line 1,<br />
Address line 2</p>
<p>phone number</p>
<p><a href="http://www.example.com" target="_blank">www.example.com</a></p>
</div>'
如何在不删除字符之间的正常间距的情况下取出所有这些新行?
【问题讨论】:
-
为什么不编写一个简单的正则表达式来删除行尾/空格/行尾等序列?
-
尝试使用 nl2br()。 php.net/manual/en/function.nl2br.php
-
我也尝试过
$tmpmaptext = preg_replace('/\s+/', '', $tmpmaptext);,但删除所有间距太过分了。我不知道删除新行的正则表达式,否则我会尝试。 -
@VinceKronlein
\n是换行符,\r是回车符。将字符放在方括号中以匹配集合中的任何字符。此外,您可能希望将其替换为单个换行符,而不是空字符串。
标签: javascript php regex