2013-06-20 69 views
1

檢索到的字符串我有沒有運氣嘗試了不少事情至今:刪除 n從DB

我使用TinyMCE的,這是我通過mysql_real_escape_string運行(),然後添加到數據庫中。

繼承人存儲在數據庫中的字符串這就是一個例子:

<p>It would be nice to be able to put this in 2 categories....</p>\n<p>something to think about.</p>

我檢索數據,然後我得到的問題。我無法擺脫\ n

$字符串=數據庫條目上述

$string = substr($item['body'], 0, 120). "..."; 
$item['bodysum'] = nl2br(stripslashes(str_replace("\n", "<br />", $string))); 

上市這裏是輸出的照片。

enter image description here

我只是希望它是正常的HTML。如果可能的話,我想將它全部轉換爲一行,而不是使該部分變大。它應該是某人發佈內容的摘要,因此讓它將總結區域放大一個字,然後換一個新行就沒有意義了!

+0

一件事 - 你不需要'\ r','\ N'或'\ r \ N'的HTML代碼,離開它,因爲是在一行,沒關係,不影響性能,事實上,它更快,更輕。 –

+0

我想你可能會倒退。嘗試'$ item ['bodysum'] = nl2br(stripslashes(str_replace(「\ n」,「
」,$ item)));' - 看看有什麼。或者,'$ item ['bodysum'] = nl2br(stripslashes(str_replace(「\ n」,「」,$ item)));' –

+0

@fred似乎不起作用。仍然得到相同的輸出與'n'漂浮在那裏 –

回答

1

是, 「\ n」 字符 「\」,其次是 「N」 ?如果是這樣的話,那就試試:

$item['bodysum'] = nl2br(str_replace("\\n", "<br />", $string)); 
+0

這工作。謝謝。 –

1

先嚐試strip_slashesnl2br

$item['bodysum'] = nl2br(stripslashes($string)); 
+0

試過這個。仍然是浮動的n? –

1

試試這個

$text = '<p>It would be nice to be able to put this in 2 categories....</p>\n<p>something to think about.</p>'; 

echo preg_replace('#(\\\r|\\\r\\\n|\\\n)#', '<br/>', $text); 

EXAMPLE HERE