Thanks for your help BobRay, it helped me get things underway.
Of course, I’ve stumbled fairly soon after solving out the syntax I need to use (I think). I figured I could use the ereg_replace function:
<?php
$string = 'A link to <a href="#ref-1">reference 1</a>';
echo ereg_replace('(<a href="#ref-(.*)">)', '<a onclick="highlight(\'ref-\\2\',\'#ffffff\',1000);" href="#ref-\\2">', $string);
?>
This seems to do the trick, but when I try to call it in MODx using my adjusted version of the AnchorsAway plugin, only part of the desired html is actually replaced. The plugin I have created looks like this (NOTE: I do not use the php tags in the plugin):
<?php
$e= & $modx->Event;
switch ($e->name) {
case "OnWebPagePrerender" :
if($modx->documentIdentifier != $modx->config['site_start']) {
$modx->documentOutput= ereg_replace('(<a href="#ref-(.*)">)', '<a onclick="highlight(\'ref-\\2\',\'#ffffff\',1000);" href="' . $modx->makeUrl($modx->documentIdentifier) . '#ref-\\2">', $modx->documentOutput);
}
break;
}
?>
When I run this I am returned with the following html:
<a onclick="highlight('ref-1">
instead of the desired:
<a onclick="highlight('ref-1','#ffffff',1000);" href="#ref-1">
I don’t suppose anyone knows what I have done wrong?
Additionally, this only "works" (I use that word loosely as it isn’t working) when I have the AnchorsAway plugin disabled... But of course both these plugins should conflict with one another! Thing is, I have no idea why?
Any help is appreciated
JB