Html 如何将格式化应用于多个div上的文本区域。

Html 如何将格式化应用于多个div上的文本区域。,html,parsing,html-parsing,Html,Parsing,Html Parsing,我有下面的html <div>this is line 1 {start-hidden}</div> <div>this is line 2</div> <div>{end-hidden} this is line 3</div> 然后删除$INTERNAR中新行的任何原因。只删除那些关闭标签太多 // attempt to remove all sources of new lines $inner = preg_rep

我有下面的html

<div>this is line 1 {start-hidden}</div>
<div>this is line 2</div>
<div>{end-hidden} this is line 3</div>
然后删除$INTERNAR中新行的任何原因。只删除那些关闭标签太多

// attempt to remove all sources of new lines
$inner = preg_replace('#<br([^>])*>#is', '', $inner);
$inner = preg_replace('#<div([^>])*>(.*?)</div>#is', '', $inner);
$inner = preg_replace('#<p([^>])*>(.*?)</p>#is', '', $inner);
使用跨度:

<div>this is line 1 <span style="visibility:hidden;">{start-hidden}</span></div>
<div>this is line 2</div>
<div><span style="visibility:hidden;">{end-hidden}</span> this is line 3</div>
这是第1行{开始隐藏}
这是2号线
{end hidden}这是第3行

是否必须将{start hidden}和{end hidden}按原样放在和标记中? 坚持html会建议使用以下内容(让样式像您的建议那样“破坏”div是没有意义的):

这是第1行
这是2号线
这是3号线
或者,正如格雷德所建议的那样:

<div>this is line 1</div>
<div style="visibility:hidden;">this is line 2</div>
<div>this is line 3</div>
这是第1行
这是2号线
这是3号线

编辑:查看一下
display:none
visibility:hidden
之间的区别很重要:

您不能以标记可以用div隐藏的块的方式生成HTML代码吗?你为什么一定要做那种陈述?这不是我想要的。我需要把这两个之间的一切都隐藏起来。所以“这是第二行”也应该隐藏起来。哦。。。知道了!在这种情况下,您应该尝试在一个html元素中生成所有隐藏部分的html代码——正如其他人在您的问题中建议的那样——出于许多原因,哪一个是最佳解决方案,或者在我的代码中,也可以在第二个div中添加可见性隐藏css样式?这可能会有点难编码我不知道你在用什么技术!是的,开始隐藏和结束隐藏可以在任何地方,可以有任何东西在里面。我无法控制输入。好的,正如你在关于“交叉”的另一个问题中提到的,你试图做的是无效的html。在父元素有结束标记之前,另一个元素中的每个html元素都需要有一个结束标记。您需要更好地解释您想要对代码执行的操作。如果您知道{start hidden}和{end hidden}将始终存在,那么您应该在div内部的部分上使用一个span,并将第二个div隐藏起来。否则,您需要在服务器端代码中涵盖这些情况。我知道这是无效的HTML,所以我们要求另一种解决方案。我用regex发布了一个(相当讨厌的)解决方案(参见问题编辑)。
$inner = '<span class="hidden">' . $inner . '</span>';
$source  = $pre;
$source .= $inner;
$source .= $post;
<div>this is line 1 <span style="visibility:hidden;">{start-hidden}</span></div>
<div>this is line 2</div>
<div><span style="visibility:hidden;">{end-hidden}</span> this is line 3</div>
<div>this is line 1</div>
<div style="display:none;">this is line 2</div>
<div>this is line 3</div>
<div>this is line 1</div>
<div style="visibility:hidden;">this is line 2</div>
<div>this is line 3</div>