2009-06-24 67 views
7

1'm試圖找出如何包裝文字是這樣的:環繞文本在P標籤

足球運動員宏,增強生活 Laoreet足球,紙箱本身。 熱坐直枕頭。一時間,我的 現在需要laoreet。 微波卡通是 層在鍵盤上,開發商之前我跑步是不是

規劃Mauris消費者和環境。保護者 軟的球員從沙拉總是裝點。 整數現在是純蛋白質和 足球,但是,它需要冰箱。即使 爲我處理生活在巡迴賽上

到這一點:

< P>足球運動員宏,增強生活 Laoreet足球,紙箱本身。 熱坐直枕頭。一時間,我的 現在需要laoreet。 微波卡通是 層在鍵盤上,開發商之前我跑步是不是</P>

< P>規劃Mauris消費者和環境。保護者 軟的球員從沙拉總是裝點。 整數現在是純蛋白質和 足球,但是,它需要冰箱。即使 爲我處理生活在巡迴賽上</P>

注意周圍的文本在P標籤。

+0

Kohana中你是一個男人!看看`文本:: auto_p()`:) – alex 2010-10-28 20:35:08

+0

1的時間不知道的Kohana的!謝謝,呵呵 – 2010-10-29 16:11:38

回答

8

這應該這樣做

$text = <<<TEXT 
Morbi nisl tortor, consectetur vitae laoreet eu, lobortis id ipsum. Integer scelerisque blandit pulvinar. Nam tempus mi eget nunc laoreet venenatis. Proin viverra, erat at accumsan tincidunt, ante mi cursus elit, non 

congue mauris dolor ac elit. Maecenas mollis nisl a sem semper ornare. Integer nunc purus, dapibus nec dignissim sed, dictum eget leo. Etiam in mi ut erat pretium fringilla sed 
TEXT; 

$paragraphedText = "<p>" . implode("</p>\n\n<p>", preg_split('/\n(?:\s*\n)+/', $text)) . "</p>"; 
2
$str = '<p>'. str_replace('\n\n', '</p><p>', $str) .'</p>'; 

OR

$str = '<p>'. preg_replace('\n{2,}', '</p><p>', $str) .'</p>'; 

爲了趕上2以上。

+0

錯字:$海峽= '

'。 ereg_replace($ STR = '\ n \ n', '

')「。

「; – racerror 2009-06-24 21:44:57

+0

謝謝主席先生,固定,我忘了參數的順序了。當 – 2009-06-24 21:46:05

3

使用preg_replace一個遍歷所有行內的輸入

$replacement = preg_replace("/(.*)/", "<p>$1</p>", $current_line);