我有:
$body = '
<div id="one">
<div id="two">
<div class="sub">
<span class="text"><a class="here" href="/aaa.php">ttt</a></span>
</div>
<span class="f">aa</span>
<div class="sub2">
<a class="here" href="/bbb.php">ttt</a>
<div>
<a class="here" href="/ttt.php">ttt</a>
</div>
<a class="here" href="/ddd.php">ttt</a>
</div>
<div class="sub">
<a class="here" href="/zzz.php">ttt</a>
</div>
</div>
</div>
';
我怎样才能从标签“a”的所有href中获取到数组?我想收到:
Array
(
[0] => /aaa.php
[1] => /bbb.php
[2] => /ttt.php
[3] => /ddd.php
[4] => /zzz.php
)
AND NEXT 我想在变量 $body 中将属性 url 更改为“/test-aaa.php-123”、“/test-bbb.php-123”等。所以我想收到:
$body = '
<div id="one">
<div id="two">
<div class="sub">
<span class="text"><a class="here" href="/test-aaa.php-123">ttt</a></span>
</div>
<span class="f">aa</span>
<div class="sub2">
<a class="here" href="/test-bbb.php-123">ttt</a>
<div>
<a class="here" href="/test-ttt.php-123">ttt</a>
</div>
<a class="here" href="/test-ddd.php-123">ttt</a>
</div>
<div class="sub">
<a class="here" href="/test-zzz.php-123">ttt</a>
</div>
</div>
</div>
';
我可以用 javascript 做这个,但我必须使用这个 PHP。有可能吗?