Note that there are some explanatory texts on larger screens.

plurals
  1. POhtmlspecialchars() issue with removing the < from </a> in string
    primarykey
    data
    text
    <p>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:</p> <pre><code>$value['CATNAME'] = htmlspecialchars($value['CATNAME']); echo '&lt;a href="somepage.php?parms=foo"&gt;'. $value['CATNAME']. '&lt;/a&gt;'; </code></pre> <p>All of the links are coming out correctly, except the bad one. It is being echo'd as</p> <pre><code>&lt;a href="somepage.php?parms=foo"&gt;AR North/a&gt; </code></pre> <p>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.</p> <p>Thanks.</p> <p>EDIT: Update</p> <p>More detailed code with what I am trying now:</p> <pre><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 '&lt;li id="catSel"&gt;&lt;a href="page.php?id=' . $value['parm1'] . '&amp;amp;pl=' . $_SESSION['parm2'] . '"&gt;' . $value['CATNAME'] . '&lt;/a&gt;'; else echo '&lt;li&gt;&lt;a href="page.php?id='. $value['parm1']. '&amp;amp;pl='. $_SESSION['parm2']. '"&gt;'. $value['CATNAME']. '&lt;/a&gt;'; </code></pre> <p>Is still giving me</p> <pre><code>&lt;li&gt;&lt;a href="somepage.php?id=185&amp;amp;pl=10"&gt;AR North/a&gt;&lt;/li&gt; </code></pre> <p>But if I change the last line to</p> <pre><code>$value['CATNAME']. '&lt;/a&gt;'; to $value['CATNAME']. ' &lt;/a&gt;'; </code></pre> <p>I get </p> <pre><code>&lt;li&gt;&lt;a href="catview.php?id=185&amp;amp;pl=10"&gt;AR North &lt;/a&gt;&lt;/li&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload