CKEditor在我的數據庫中輸入的內容中添加了新行,這很好,除了需要將這些數據以javascript形式呈現爲一行html。在PHP中刪除換行符和換行符
在我的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()。 http://php.net/manual/en/function.nl2br.php – Ali
我也嘗試過'$ tmpmaptext = preg_replace('/ \ s + /','',$ tmpmaptext);'但是這太過於刪除所有間距。我不知道刪除新行的正則表達式,或者我會嘗試。 –