可能重复:
How do you parse and process HTML/XML in PHP?读内容在HTML div标签PHP
目前,我有一个代码片段看起来像这样:
echo '<div id="content">';
echo '<b>Results:<br></b>';
echo '<div style="margin-right: 230px; margin-top: -20px;"><center><a href="http://clubpenguincheatsnow.com/tools/itemdatabase/"><b>Back</b></a><center></div>';
$string = explode('<br>', $string);
foreach ($string as $row) {
preg_match('/^(.+)\s=\s(\d+)\s=\s(\D+)\s=\s(\d+)/', trim($row), $matches);
if (preg_match("/$query/i", "$matches[1]")) {
echo "<a href='http://clubpenguincheatsnow.com/tools/itemdatabase/info.php?id=$matches[2]'>";
echo $matches[1];
echo "</a><br>";
}
}
echo '</div>';
正如你可以看到我有顶部和底部的div标签echo '<div id="content">';
echo '</div>';
。我想要做的是我的PHP代码来扫描两个标签之间的输出,如果文本<b>Results:<br></b><div style="margin-right: 230px; margin-top: -20px;"><center><a href="http://clubpenguincheatsnow.com/tools/itemdatabase/"><b>Back</b></a><center></div>
位于标签之间,我希望我的代码输出“Test”。任何有关我的问题的帮助将是非常有益的!
使用DOM解析器来处理HTML,而不是正则表达式! – Brad
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Crontab