I've sorted this out now. The last column in my html table is a hyperlink to another page. It has details of the references input by the user. This hyperlink was terminating at the single quote. As the references on the next page are for display only, I did a replace(string,"'","***") in the hypherlink and a replace(string,"***","'") on the next page. I know it's not elegent but it will do for now.
Thanks for the help (again) Kodo.