arianhojat Posted May 17, 2006 Share Posted May 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/9871-htmlentities-versus-htmlspecialchars/ Share on other sites More sharing options...
obsidian Posted May 17, 2006 Share Posted May 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/9871-htmlentities-versus-htmlspecialchars/#findComment-36677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.