Rob
Rob

Reputation: 6370

Strip out special characters in php

I have the code below:

<?php echo $fields->question; ?>

I specifically want to strip out any special characters that may cause an issue with php, how could I do that? Specifically "" is causing me a problem at the moment.

Upvotes: 0

Views: 278

Answers (2)

max4ever
max4ever

Reputation: 12142

<?php echo htmlentities($fields->question, ENT_QUOTES, "UTF-8")?>

Upvotes: 2

Evernoob
Evernoob

Reputation: 5561

Have you tried the addslashes() native PHP function?

$foo = addslashes($fields->question);
echo $foo;

This won't strip them out, but it should prevent them from causing you any problems by escaping the quotes.

Upvotes: 1

Related Questions