htmlspecialchars() issue with removing the < from </a> in string

I am pulling some category names from a table, and I am using htmlspecialchars() to process the string that I get back for the category name. The problem is that one out of hundreds of category names is being echo'd with a bad closing tag. This is a simplified version of the string I am echoing:\[code\]$value['CATNAME'] = htmlspecialchars($value['CATNAME']);echo '<a href="http://stackoverflow.com/questions/10542122/somepage.php?parms=foo">'. $value['CATNAME']. '</a>';\[/code\]All of the links are coming out correctly, except the bad one. It is being echo'd as\[code\]<a href="http://stackoverflow.com/questions/10542122/somepage.php?parms=foo">AR North/a>\[/code\]Without the htmlspecialchars() line commented out, it's output with the correct closing tag. I looked at the string in the table and there's nothing wrong with it there either. Does this seem like a PHP issue, or should I be looking elsewhere? I am suspecting that maybe there is some javascript messing with the tags, that's where I plan on looking next.Thanks.EDIT: UpdateMore detailed code with what I am trying now:\[code\] // Convert characters with special HTML significance $value['CATNAME'] = utf8_encode($value['CATNAME']); $value['CATNAME'] = htmlspecialchars($value['CATNAME']); // Print the list item. If the currently selected Id is equal to the category being listed indicated so by marking it if ($selectedCat === $value['CATID']) echo '<li id="catSel"><a href="http://stackoverflow.com/questions/10542122/page.php?id=' . $value['parm1'] . '&pl=' . $_SESSION['parm2'] . '">' . $value['CATNAME'] . '</a>'; else echo '<li><a href="http://stackoverflow.com/questions/10542122/page.php?id='. $value['parm1']. '&pl='. $_SESSION['parm2']. '">'. $value['CATNAME']. '</a>';\[/code\]Is still giving me\[code\]<li><a href="http://stackoverflow.com/questions/10542122/somepage.php?id=185&pl=10">AR North/a></li>\[/code\]But if I change the last line to\[code\]$value['CATNAME']. '</a>'; to $value['CATNAME']. ' </a>';\[/code\]I get \[code\]<li><a href="http://stackoverflow.com/questions/10542122/catview.php?id=185&pl=10">AR North </a></li>\[/code\]
 
Back
Top