It’s times like this when it’s difficult not to name a thread "What the Heck!?!"
I have a snippet running on my website called MakeURLSafe, which is designed to pass URLs and other address-embedded strings into, so that it can replace illegal or otherwise trouble-causing characters and symbols with URL entities, e.g. replacing spaces with "%20", qoutations with "%22", and so on. The snippet looks like this:
<?php
//takes &string as parameter
$search = array('"',':','/','?','#quest;','#equal;','=','&','#',' ');
$replace = array('%22','%3A','%2F','%3F','%3F','%3D','%3D','%26','%23','%20');
$string = str_replace($search,$replace,$string);
return $string;
?>
It worked when I first created it, but sometime between that time (about a week or so ago) and last night, it stopped working. I ran this code by itself in a test php document, echoing the result instead of returning it, and it worked fine. The test string I used was
Desktops for "Chipmunk Loses"
The result was:
Desktops%20for%20%22Chipmunk%20Loses%22
That probably seems like an awfully arbitrary test choice. If you go to my site, it makes more sense why I chose it; it’s the title of my latest post, which might get embedded in a share link sent to Delicious or something.
Anyway, the snippet works fine when ran solo in a test php document, and returns the expected result. But when I run it in as an actual snippet under MODx, it returns the string as it received it, completely unformatted. I ran some further tests and found that the string was, in fact, being successfully, completely, and accurately passed to the snippet, and I traced its path and found that it was also being passed all the way through the snippet successfully. But the return value doesn’t appear to be effected by the str_replace function.
Any clues why this might be failing? All help much appreciated.