Page 1 of 1

html entities

Posted: Sun Mar 26, 2006 7:22 pm
by s.dot
I have a database field that may or may not contain html

One instance may be

Code: Select all

<a href="#">link here</a>
and another instance may be

Code: Select all

<a href="#">link here</a>
My problem comes when displaying these in a textarea field. Obviously I want to show the html as text, so in both cases the html should show up as

Code: Select all

<a href="#">link here</a>
I'm not sure how to do this, but I was thinking something along these lines

Code: Select all

$text = htmlentities(html_entity_decode($databasetext,ENT_QUOTES),ENT_QUOTES);
echo "<textarea>$text</textarea>";
Is there any case where this would mess up? For instance if the user wrote out an entity as text like " but the message was stored in HTML.

Would this still show up fine?

I can't seem to wrap my mind around the idea.

Posted: Sun Mar 26, 2006 7:36 pm
by s.dot
Lets say that the message is stored in HTML

but the part of it was typed in as entities, like this

Code: Select all

<a href="#">stuff</a>

<a href="#">stuff</a>
Now, when I pull this out into the textarea, I would like it to look exactly like that. With that current way of doing it it shows up like this:

Code: Select all

<a href="#">stuff</a>

<a href="#">stuff</a>
However if its stored in entities instead of HTML it comes out like its supposed to

Code: Select all

<a href="#">stuff</a>

<a href="#">stuff</a>
I hope I am making sense.

Posted: Sun Mar 26, 2006 7:46 pm
by s.dot
OK I think I have it solved

Code: Select all

echo '<textarea>';
if($approve_a['pref_profile_comment_html'] == 1){
    //  it was stored in entities, so just show it
	echo $cment;
} else {
    //  it was stored in html, so show the entities
	echo htmlentities($cment,ENT_QUOTES);
}
echo '</textarea>';
Does that look correct?