Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape only single quotes (leave double quotes alone) with htmlspecialchars()

I know there are other ways of of escaping only single quotes (such as this answer), but it appears to me that there should be a way using htmlspecialchars().

According to the manual, it should be some combination of their constants, but based on their explanations, I don't see it.

Is it possible to escape only single quotes, leaving the double quotes alone, with htmlspecialchars()?

like image 241
Luke Shaheen Avatar asked May 14 '12 21:05

Luke Shaheen


1 Answers

str_replace("'", "\\'", $string);

There.

Or, use ENT_QUOTES

htmlspecialchars($string, ENT_QUOTES);
like image 183
Norse Avatar answered Sep 27 '22 23:09

Norse