我試圖讓用戶可以將表添加到他們的帖子,我遇到的問題,在另一個功能我使用nl2br
使它會自動添加換行符。儘管桌子是如何工作的,但所有的換行符都會超過它,從而產生大量的空間。我在下面提供了一張圖片,以便能夠看到我的意思。我嘗試使用\r\n
或\n
,但我覺得我要麼使用它錯誤,要麼在這種情況下不起作用。刪除字符串的特定部分之間的空格/換行符
function markupDoc($post){
//tables
while(($post2 = preg_replace("/\[td]((?:(?!\[td\]).)+?)\[\/td\]/s", '<td>\\1</td>', $post)) !== $post){
$post=$post2;
}
while(($post2 = preg_replace("/\[tr]((?:(?!\[tr\]).)+?)\[\/tr\]/s", "<tr>\\1</tr>", $post)) !== $post){
$post=$post2;
}
while(($post2 = preg_replace("/\[thead]((?:(?!\[thead\]).)+?)\[\/thead\]/s", '<thead>\\1</thead>', $post)) !== $post){
$post=$post2;
}
while(($post2 = preg_replace("/\[table]((?:(?!\[table\]).)+?)\[\/table\]/s", '<table class="table table-striped table-bordered">\\1</table>', $post)) !== $post){
$post=$post2;
}
return $post;
}
字符串我正在提交:
going to
[table]
[thead]
[td]test[/td]
[td]test[/td]
[td]moo[/td]
[td]a[/td]
[/thead]
[tr]
[td]test[/td]
[td]moo[/td]
[/tr]
[tr]
[td]test[/td]
[td]test[/td]
[td]moo[/td]
[td]a[/td]
[/tr]
[/table]
你能後的實際原始輸出,而不是一個形象? – hwnd
它在表格上方返回'
'標籤,因爲它不在一行(我提交的字符串,它使用'nl2br')。我添加了我正在使用的字符串。我用來測試的開發者網站就在這裏:http://beta.projectdonut.me/docs/v/1385253660-documentation_Demo/updated如果有人想查看頁面如何呈現它。 – Jake
您是否想要移除'
'標記?還是全部空白? – hwnd