【发布时间】:2011-08-13 22:06:53
【问题描述】:
我需要获取一串html文本,例如:
<p>This is a line with no spans<br>
This is a line <span class="second">This is secondary</span><br>
This is another line <span class="third">And this is third</span> <span class="four">this is four</span></p>
并让它在 PHP 中作为一个数组结束,例如:
array(
"This is a line with no spans",
array(
"This is a line",
second => "This is secondary",
),
array(
"This is another line",
third => "And this is third",
four => "this is four"
)
);
让每一行变成它自己的值很容易,我只是在
上分割文本,效果很好,但是用类名分割行我不太明白。我觉得 php 的 preg_split 可能是关键,但我对正则表达式有点烂,我无法弄清楚。
有什么想法吗?
【问题讨论】: