htmlspecialchars problems

  • DavyDuke17
  • Graduate
  • Graduate
  • DavyDuke17
  • Posts: 166

Post 3+ Months Ago

In my database I have a text field that holds articles that can include html tags such as links, bold, ect. However, it also has alot of regular text that may have quotes and other characters that need to be converted using htmlspecialchars. However, when I use the htmlspecialchars function it also converts the tags and quotes inside of the tags into there html entities which I do not because when I echo it out I want the links, ect to show up.

Any work arounds to get htmlspecialchars to not convert tags, but everything else?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Truce
  • Guru
  • Guru
  • Truce
  • Posts: 1477
  • Loc: Washington DC

Post 3+ Months Ago

preg_replace_callback is your friend. You should probably consider escaping the relevant text on input, though, rather than output since doing a recursive preg_replace_callback is a bit of an expensive task and it'd make more sense to store the results than to have to execute it on every call.

Alternately, you can just do a preg_replace and only replace characters that fall outside of < and >.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 63 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.