Jump to content

Recommended Posts

I need a clear explanation about when exactly htmlentities() is more useful versus htmlspecialchars() if anyone can help.

Anyone want to take a stab at explanation?
my best guess is htmlspecialchars() only does whats needed(' " & < >) so it seems like the default choice when need to pull database values and put them into html (which needs those chars escapes). But when would you need to convert all chars to their equivalents (i know there are probably alot of scanarios but was looking for common things you see in web programming)? Someone told me encoding/decoding values into the query string, but wasnt sure.
Link to comment
https://forums.phpfreaks.com/topic/9871-htmlentities-versus-htmlspecialchars/
Share on other sites

as far as a defining the differences between the two, i think the manual itself does that the best:
[quote]
This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.
[/quote]

as for one example when you might want to translate all characters to their equivalents may be if you're creating an RSS feed or generating XML or XHTML through the PHP. for [i]best practices[/i], it's good to use entities rather than the symbols themselves whenever possible.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.