I know this isn’t really the place to learn PHP, but this should be simple, I think. There’s a Wordpress plugin called
Widon’t that’s been ported to a number of CMS. The heart of it is this:
preg_replace( '|([^\s])\s+([^\s]+)\s*$|', '$1 $2', $str);
It is supposed to replace the space between the last two words of a string with a The help doc at
http://svn.modxcms.com/docs/display/revolution/Plugins gives this example of text parsing:
$words = array("snippet", "template"); // words to filter
$output = &$modx->resource->_output; // get a reference to the output
$output = str_replace($words,"<b>[filtered]</b>",$output);
And says to register it with the OnWebPagePrerender event. By analogy, then, I thought something like this:
$output = &$modx->resource->_output;
$output = preg_replace( '|([^\s])\s+([^\s]+)\s*$|', '$1 $2', $output);
would do the trick, but it doesn’t.
Would someone please tell me why it doesn’t and what will?