Link removal (JS Regex)

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Wowee! That look just the thing...nearly.

This only seems to work for the first link it finds on the page!?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

ehh.. I had problems with + in quick-reply box, check the for loop, does it contain i++ ?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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'");
}
Post Reply