Automatic Purification of Link URIs

I think most of my trouble here is a fundamental misunderstanding of how HTMLPurifier works (probably because I was tossed into a project where it already implemented and hidden via a framework).

Essentially, we allow HTML comments and are using HTMLPurifier to purify them on display. The comments allow links but it appears the URIs are not being encoded to the degree we want (or at all). The particular example we were given was a URL such as http://www.example.com/alert(document.cookie). In our case, we need to encode the parentheses and any other character that may be a vulnerability. It was pointed out that this was not being done by default, so I implemented a solution using straight PHP to pull out the hrefs and perform some encoding on them. Since I don't know just how good the solution in, I started googling around and, via a couple of threads on here, tried to use the following: