Not sure why that is happening, I have actually managed to make it only interlink the first keyword it sees now thanks to the genius that is MrHaw! I now need to work out how to set the number of keywords in that variable so I can change at will. Next mission is to also work out how to make it look for 3 keywords per page.
This is the code I am using in the actual plugin:
$output = &$modx->documentOutput;
$output = replace_first(" madonna ", '<a href="madonna.html"> madonna </a>', $output);
return $output;
I also added this to the end of my manager/includes/document.parser.class.inc.php document:
function replace_first($search, $replace, $data) {
$res = strpos($data, $search);
if($res === false) {
return $data;
} else {
// There is data to be replaced
$left_seg = substr($data, 0, strpos($data, $search));
$right_seg = substr($data, (strpos($data, $search) + strlen($search)));
return $left_seg . $replace . $right_seg;
}
}
The Wordpress one works like a dream, I am sure we can create the same thing for MODX!