Reputation: 497
I have the following variable being dynamically set by user generated content:
$variable = '<a href="http://www.mysite.com/article">This Article</a>';
When this variable is set, I then echo it as such
echo $variable;
I know that as is, this wouldn't be valid because I would need to escape the double quotes etc.
Is there a way to automate the process to make the variable printable as a clickable link, thus escaping the quotes in my variable automatically?
Edit: Turns out this is indeed perfectly valid, but this being used on a joomla site, html tags are being stripped out, and I have to use [[a href]] instead of the regular <>. Thanks everyone for your help!
Upvotes: 1
Views: 8323
Reputation: 261
I tried to use your exact code in a php page I have and it acts as you need it to. Seems to be working just fine for me.
Upvotes: 2
Reputation: 338118
To display the string "as it is" in a browser, you must pass it through htmlspecialchars()
.
echo htmlspecialchars($variable);
If you don't, the browser interprets the HTML and displays the link text, as expected.
Upvotes: 7
Reputation: 666
I don't see a problem with your code as-is... You're using single quotes to contain the entire string, so it should output as a clickable link when viewed in a browser
Upvotes: 2