以下是我的示例html代码
<section class="well well-2" style="background-color:#eee">
<div class="container">
<div class="row">
<div class="col-md-4 text-center">
<h3 style="color:#CC0000">Car Bumper</h3>
<p>Entrusting upon credible vendors for high-grade raw materials, we manufacture and supply premium quality Car Bumper.</p>
<a href="car_bumper.php" class="btn btn-lg btn-yellow-green">...More</a>
</div>
<div class="col-md-4 text-center">
<h3 style="color:#CC0000">Car Body Kits</h3>
<p>Enriched with a vast industry experience, we are capable of manufacturing and supplying best quality Car Body Kits.</p>
<a href="car_bodykitss.php" class="btn btn-lg btn-yellow-green">...More</a>
</div>
<div class="col-md-4 text-center">
<h3 style="color:#CC0000">Car Alteration</h3>
<p>We are a credible name that is occupied in the business of manufacturing and supplying of best quality Car Modification Kit.</p>
<a href="car_alteration.php" class="btn btn-lg btn-yellow-green">...More</a>
</div>
</div>
<div class="row">
<div class="col-md-4 text-center">
<h3 style="color:#CC0000">Car Styling Kits</h3>
<p>We are one among the prominent manufacturers and suppliers of a wide array of Car Styling kits with perfect finishing.</p>
<a href="car_stylingkit.php" class="btn btn-lg btn-yellow-green">...More</a>
</div>
<div class="col-md-4 text-center">
<h3 style="color:#CC0000">Car Painting Services</h3>
<p>Painting requires special expertises, we paint cars , which offers ultraviolet blockers in the clear coat.</p>
<a href="car_painting.php" class="btn btn-lg btn-yellow-green">...More</a>
</div>
<div class="col-md-4 text-center">
<h3 style="color:#CC0000">Car Spoiler</h3>
<p>We are listed at the acme for manufacturing and supplying an ample range of best quality Car Spoilers.</p>
<a href="car_spoiler.php" class="btn btn-lg btn-yellow-green">...More</a>
</div>
</div>
</div>
</section>
从这页内容中,我通过以下PHP代码检索标记内容,
<?php
include('simple_html_dom.php');
$filename='index.php';
$dom = file_get_contents($filename);
$html = file_get_html($filename);
$h3=array();
$p=array();
$tags = get_meta_tags($filename);
foreach($html->find('h3') as $element) { ?>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">H3</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="h3[]" id="h3[]" value="<?php echo $element->innertext; ?>">
</div>
</div>
<?php $k++; foreach($html->find('p') as $element) {?>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Paragraph</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="p1[]" name="p1[]" value="<?php echo $element->innertext; ?>">
</div>
</div>
<?php } $o++;
?>
这样它将检索屏幕下方的内容
但是我希望结果按照h3和它的段落以及下一个它的h3和它的段落我怎么能用这个。我不知道而且我试过很多方式请任何人帮我解决这个问题。谢谢提前。
答案 0 :(得分:2)
尝试:
With
答案 1 :(得分:0)
您是否尝试过为2个循环使用单独的变量?我看到你正在使用$element
进行两个似乎不合适的循环。