简体   繁体   中英

problems displaying html characters

I'm building a sign-in/up form and I have problems displaying HTML characters. When a user signs up, I use this function for the sign-up data and then insert it into the database.

function clearInput( $string) {
  $string = stripslashes($string);
  return htmlentities($string);
}

When a user signs-up with the name <p>hello</p> it will look like this in the db: "&amp;lt;p&amp;gt;hello&amp;lt;/p&amp;gt"<br> .

If the user signs-in and I var_dump the name that is saved in the session it looks like this <br>'&lt;p&gt;hello&lt;/p&gt;' in the browser.

If I echo this &lt;p&gt;hello&lt;/p&gt; manually in the document, it displays this <p>hello\</p> as it should normally.

Does someone know how it shows <p>hello</p> when I var_dump the session name?

I don't get your question but it will help you.

$str = "This is some &lt;b&gt;bold&lt;/b&gt; text.";
echo htmlspecialchars_decode($str);
This is some <b>bold</b> text.


$str = '&lt;a href=&quot;https://www.test.com&quot;&gt;test.com&lt;/a&gt;';
echo html_entity_decode($str);
<a href="https://www.test.com">test.com</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM