We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    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
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Shit! Two day, and it turns out I was using the wrong event! rolleyes I needed OnWebPagePrerender! I had to pick through the parser code to follow the content! Now it works great! I think this calls for ice cream.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org