Page 2 of 2

Posted: Thu Jun 01, 2006 10:43 am
by JayBird
Wowee! That look just the thing...nearly.

This only seems to work for the first link it finds on the page!?

Posted: Thu Jun 01, 2006 11:17 am
by Weirdan
ehh.. I had problems with + in quick-reply box, check the for loop, does it contain i++ ?

Posted: Thu Jun 01, 2006 11:24 am
by JayBird
Aha! That's done it.

Works like a treat. Thanks, really appreciate it.

Now i need to really understand how it works.

Off to google i go :D

Posted: Thu Jun 01, 2006 6:32 pm
by Weirdan
It queries all required nodes using Xpath, then iterates over the results and replaces them accordingly.
XPath to DOM is like SQL to RDBMS :)... much like:

Code: Select all

$res = mysql_query("
   SELECT
      `link`.`id` as `link_id`,
      `font`.`id` as `font_id`,
      `font`.`content`
   FROM 
      `DomElements` `link` 
   INNER JOIN 
       `DomElements` `font` 
   ON `font`.`parent` = `link`.`id`
   WHERE
       `link`.`nodeName` = 'A'
       AND `font`.`nodeName` = 'FONT'
       AND `link`.`target`
");
while(list($link_id, $font_id, $content) = mysql_fetch_row($res)) {
    mysql_query("DELETE FROM `DomElements` WHERE `id` in ($link_id, $font_id)");
    mysql_query("INSERT INTO `DomElements` SET `nodeName` = `text`, `content`='$content'");
}