我试图让用户可以将表添加到他们的帖子,我遇到的问题,在另一个功能我使用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