Displaying HTML code in textarea. How?

Bruce Gust
Bruce Gust used Ask the Experts™
on
Here's what I've got in my source code:

<textarea name="metatags"><META NAME="DESCRIPTION" CONTENT="RTA Kitchen Cabinets Online, Wholesale Kitchen Cabinets, Buy RTA Cabinets Online, Maple RTA Cabinets"> <META NAME="ABSTRACT" CONTENT="RTA Cabinets, Maple Cabinets, Wholesale Cabinets, Buy Cabinets Online"> <META NAME="KEYWORDS" CONTENT="RTA Cabinet,RTA Kitchen Cabinets, Maple Cabinets, Kitchen Cabinets, buy kitchen cabinets, buy cabinets online, cabinets, rta cabinets, cabinet maker"> </textarea>

This is the result of my doing this:

<textarea name="metatags"><?php echo htmlspecialchars_decode($row['metatags']); ?></textarea>

I'm not seeing anything. My textarea is blank.

What do I need to change?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead
Commented:
perhaps you can try use some HTML editor instead?

for example, you can try to integrate this HTML editor into your codes:

CK Editor
http://ckeditor.com/
Brian TaoSenior Business Solutions Consultant
Top Expert 2014
Commented:
You're using the opposite of the function. What you need is htmlspecialchars().
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
Are you loading this as a *.PHP page or a *.HTML page?  If it's just HTML, the PHP code won't execute.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

srihari chanderSoftware Engineer
Commented:
try to change,

<textarea name="metatags"><?php echo htmlspecialchars_decode($row['metatags']); ?></textarea>

to

<textarea name="metatags"><?php echo htmlentities(($row['metatags']); ?></textarea>
Most Valuable Expert 2011
Top Expert 2016

Commented:
Please tell us from a high-level, non-technical perspective: What are you trying to achieve?  The <textarea> is used for HTML input - a place for a client to type information that gets sent to the server.  So this looks very unusual, to be loading a textarea up with things that are normally found in the <head> of the HTML document.  Plus, these are not valid HTML markup, but we can deal with that in another question.  For now, just tell us the objectives and we can probably show you a good way to go about things.
Most Valuable Expert 2011
Top Expert 2016
Commented:
Here is a demonstration script.  Please read the references noted in the comments - they are what you need to understand to pursue the question further.  If you look at the web page, what you see will appear to be the same, but if you use view source, you can see the difference that is hidden by the browser!
http://iconoun.com/demo/temp_brucegust.php
<?php // demo/temp_brucegust.php
/**
 * http://www.experts-exchange.com/questions/28933347/Displaying-HTML-code-in-textarea-How.html
 *
 * References:
 * http://php.net/manual/en/faq.html.php (See #2)
 * http://php.net/manual/en/function.htmlspecialchars.php
 * http://php.net/manual/en/function.htmlspecialchars.php#112476 (Note on UTF-8)
 * http://php.net/manual/en/function.htmlspecialchars-decode.php
 */
error_reporting(E_ALL);

// SIMULATE THE TEST DATA
$row['metatags'] = <<<EOD
<META NAME="DESCRIPTION" CONTENT="RTA Kitchen Cabinets Online, Wholesale Kitchen Cabinets, Buy RTA Cabinets Online, Maple RTA Cabinets"> <META NAME="ABSTRACT" CONTENT="RTA Cabinets, Maple Cabinets, Wholesale Cabinets, Buy Cabinets Online"> <META NAME="KEYWORDS" CONTENT="RTA Cabinet,RTA Kitchen Cabinets, Maple Cabinets, Kitchen Cabinets, buy kitchen cabinets, buy cabinets online, cabinets, rta cabinets, cabinet maker">
EOD;

// SIMULATE THE HTML TEXTAREA(S)
?>
<h2>Clear Text</h2>
<textarea name="metatags"><?php echo $row['metatags']; ?></textarea>

<h2>Using htmlspecialchars()</h2>
<textarea name="metatags"><?php echo htmlspecialchars($row['metatags']); ?></textarea>

<h2>Using htmlspecialchars_decode()</h2>
<textarea name="metatags"><?php echo htmlspecialchars_decode($row['metatags']); ?></textarea>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial