【发布时间】:2018-04-19 07:55:45
【问题描述】:
我想知道一种改变锚标签和图像标签以添加target='_blank'属性的方法。
我使用file_get_contents() 从外部源渲染内容并将其分配给一个变量。现在我想更改变量并将target='_blank' 属性分配给锚标记。
可以用 Drupal7 的方式还是 PHP 的方式?
<?php
$data=file_get_contents('https://example.com/live/widget/1');
?>
print_r($data);
<html>
<div>
<span class="lw_item_thumb1">
<a href="https://example.com/#!view/event/event_id/1">
<img src="https://example.com/live/image/gid/2/width/80/height/80/crop/1/src_region/0,0,3200,2400/example.rev.12345.jpg" alt="Floor" class="lw_image" width="80" height="80" srcset="https://example.com/live/image/scale/2x/gid/2/width/80/height/80/crop/1/src_region/0,0,3200,2400/example.rev.12345.jpg 2x, https://example.com/live/image/scale/3x/gid/2/width/80/height/80/crop/1/src_region/0,0,3200,2400/example.rev.12345.jpg 3x" data-max-w="3200" data-max-h="2400"/>
</a>
</span>
<span class="lw_item_thumb2">
<a href="https://example.com/#!view/event/event_id/2">
<img src="https://example.com/live/image/gid/2/width/80/height/80/crop/1/src_region/0,0,3200,2400/example.rev.12345.jpg" alt="Floor" class="lw_image" width="80" height="80" srcset="https://example.com/live/image/scale/2x/gid/2/width/80/height/80/crop/1/src_region/0,0,3200,2400/example.rev.12345.jpg 2x, https://example.com/live/image/scale/3x/gid/2/width/80/height/80/crop/1/src_region/0,0,3200,2400/example.rev.12345.jpg 3x" data-max-w="3200" data-max-h="2400"/>
</a>
</span>
</div>
</html>
我希望锚标签更改为
<a href="https://example.com/#!view/event/event_id/1" target='_blank'>
PS:我想避免使用 Javascript,而是想用 PHP 或 Drupal 的方式来做。
【问题讨论】: