gpt4 book ai didi

php - 使用 phpquery 问题删除 href

转载 作者:行者123 更新时间:2023-11-28 14:51:06 26 4
gpt4 key购买 nike

您好,我需要删除屏幕碎片网站的链接,这里是输出源。

<div class="FourDayForecastContainerInner">
<span class="day">Friday</span>
<a href="forecastPublicExtended.asp#Period4" target="_blank">
<img src="./images/wimages/b_rain.gif" class="thumbnail">
</a>
<span class="hi">
<span style="width:24px;">Hi</span>
19 / 66
</span>
<span class="lo">
<span style="width:24px;">Lo</span>
16 / 60
</span>

<span class="description">
Sunny Breaks, showers
</span>
</div>

<div class="FourDayForecastContainerInner">
<span class="day">Saturday</span>

这是我使用 phpquery 的代码

$doc = phpQuery::newDocumentHTML( $e );  
$containers = pq('.FourDayForecastContainerInner', $doc);
foreach( $containers as $container ) {
$div = pq('span', $container);
$img = pq('img', $container);
$div->eq(0)
->removeAttr('style')
->addClass('day')
->html(
pq( 'u', $div->eq(0) )
->html()
);

$img->eq(0)
->removeAttr('style')
->removeAttr('height')
->removeAttr('width')
->removeAttr('alt')
->addClass('thumbnail')
->html( pq( 'img', $img->eq(0)) );

$div->eq(1)
->removeAttr('style')
->addClass('hi');

$div->eq(3)
->removeAttr('style')
->addClass('lo');

$div->eq(5)
->removeAttr('style')
->addClass('description');
}
print $doc;

我已经设法删除了所有属性样式高度宽度等,但我似乎无法删除 a href非常感谢你的帮助

最佳答案

我用你的示例代码试过了,它有效。这是输出

<div class='FourDayForecastContainerInner'>

<span class='day'>Friday</span>

<img src='./images/wimages/b_rain.gif' class='thumbnail'>
<span class='hi'>
<span style='width:24px;'>Hi</span>
19 / 66
</span>
<span class='lo'>

<span style='width:24px;'>Lo</span>
16 / 60
</span>

<span class='description'>
Sunny Breaks, showers
</span>


</div>

<div class='FourDayForecastContainerInner'>

<span class='day'>Saturday</span><div class='FourDayForecastContainerInner'>

<span class='day'>Friday</span>

<img src='./images/wimages/b_rain.gif' class='thumbnail'>
<span class='hi'>
<span style='width:24px;'>Hi</span>

19 / 66
</span>
<span class='lo'>
<span style='width:24px;'>Lo</span>
16 / 60
</span>

<span class='description'>
Sunny Breaks, showers
</span>


</div>

<div class='FourDayForecastContainerInner'>

<span class='day'>Saturday</span>

你做的方式太长太累了。使用正则表达式替换链接。

关于php - 使用 phpquery 问题删除 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4594946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com