我想将每个值数组替换为另一个键生成的数组。
$html='
<div class="col-md-4 wow fadeInUp" data-wow-delay="0.0s">
<div class="price-item">
<div class="price-header">
<div class="price-title">
<h2>Basic</h2>
</div>
<div class="price-prices">
<h2><small>$</small>49<span>/ mo</span></h2>
</div>
</div>
<div class="price-body">
<div class="price-description">
<ul>
<li>Personal Trainer</li>
<li>Special Class</li>
<li>Free Tutorials</li>
<li>Group Training</li>
</ul>
</div>
</div>
<div class="price-footer">
<div class="price-action">
<a class="btn" href="">Join Now</a>
</div>
</div>
</div>
</div>
';
这个HTMLDOM输入是每个解析器想要替换的循环键1,2,3。。。。
$dom = new DOMDocument();
$dom->loadHTML($html);
$nodes = $dom->getElementsByTagName("*");
foreach ($nodes as $key => $node ) {
if(!empty($node->nodeValue))
if ($node->tagName=='h1' || $node->tagName=='h2' || $node->tagName=='span' || $node->tagName=='small' || $node->tagName=='h3' || $node->tagName=='a' || $node->tagName=='p' || $node->tagName=='li'){
$search[]=$node->nodeValue;
$replace[]='$'.$key.'$';
}
}
str_replace($search, $replace, $html);
输出将是两个阵列相互替换 Basic
进入 $1$
及 $49/ mo
进入 $2$
....
暂无答案!
目前还没有任何答案,快来回答吧!