PHP Quote Problems
I am always running into problems with quotes in PHP.
Here's the problem
<?php
echo strip_tags("{LINKDESCRIPTION}");
?>
{LINKDESCRIPTION} is a description of a listing on one of my sites. The description can contain all types of text. What happens if the {LINKDESCRIPTION} has a double quote in it? It creates an error. Since this is a user submitted field, I can't really restrict the use of quotes. How can I allow the double quotes? If I make it like
<?php
echo strip_tags('{LINKDESCRIPTION}');
?>
Greg K posted this at 03:49 — 12th June 2006.
He has: 2,145 posts
Joined: Nov 2003
Well, if the value of the information is submitted by a user, then it should be in a variable, in which case the quotes shouldn't matter for an echo. (using it within something like a SQL statement could cause problems though).
As you have it listed below, the string is hard coded, in that case just enter \" for a double quote. If it is in a variable, use the addslashes() function first. See http://us3.php.net/addslashes.
-Greg
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.