I have a plugin that traps the OnLoadWebDocument event. I use a preg_replace to search for local URLs, and add a value to the query string. Somehow it’s looping, and adding the value as many times as there are eligible links in the documentOutput string.
Does anyone have an idea why it’s doing that, or how I can stop it from looping so that it only adds the value once in each link?
The same preg_replace works perfectly when in a test script with the source of an html page as the iinput string, so it’s definitely the parser doing the looping.
$output = $modx->documentOutput;
$modx->documentOutput = preg_replace("#(<a[^>]+href=[^\"]'?)([^>' ]+)('?[^>]*>)#is","\\1\\2&lang=$lang\\3", $output);
http://www.sottwell.com/home.html&template=8&lang=1&lang=1&lang=1&lang=1&lang=1&lang=1&lang=1&lang=1&lang=1