满足条件时PHP更改href

问题描述

我使用 PHP foreach 循环遍历超链接数组。 如果满足条件,我想更改超链接的 href。如果没有,循环可以继续。 我可以使用以下方法来回显当前的 href: echo $node->getAttribute( 'href' ); 但是我无法使用以下方法更改它: $node->setAttribute('href',"https://www.website2.com");

在这里遗漏了一些东西,但我已经坚持了一段时间。

完整代码

  $dom = new DOMDocument;
  $dom->loadHTML($homepage);
  foreach ($dom->getElementsByTagName('a') as $node) {
    if ($node->getAttribute( 'href' ) == "https://www.website1.com"  ) {
      echo $node->getAttribute( 'href' );
      $node->setAttribute('href',"https://www.website2.com");
    }
  }
$html = $dom->saveHTML();

解决方法

也许,如果您仍然遇到问题,以下内容会有所帮助。

UPDATE TABLE_A a 
JOIN (SELECT b.col1,b.col2,b.col3
FROM TABLE_B b
GROUP BY b.col1
ORDER BY b.col2 ) x ON a.join_col = b.join_col
JOIN (SELECT c.col1,c.col2,c.col3
FROM TABLE_C c
GROUP BY c.col1
ORDER BY c.col2 ) z ON a.join_col = c.join_col
SET a.column = c.column + b.column
WHERE a.column = 'xyz'

哪个应该产生:

Example output