PHP problem! htmlspecialchars(); and htmlentities(); don't work!

Status
Not open for further replies.

Thallium

Ars Legatus Legionis
26,553
Subscriptor
Ok, here's my deal. I'm working on a page, and I store a paragraph in a MySQL database. I want to pull it back out and assign it a variable, like this:
code:<HR>
Code:
$description = htmlspecialchars($row[9]);
Where $row[9] is the row I'm pulling from in my mysql_query string. It pulls the data out fine, but the htmlspecialchars part does no good. The quotes (', ") come out with a \ in front. I tried htmlentities but that doesn't work either. Help!
 

Keyan

Ars Centurion
334
Subscriptor++
It's a little hard to tell what exactly the problem is from your description.

I'm guessing you're getting unexpected backslashes in front of the quote characters. Usually this means the data was accidentally escaped twice before being entered into the database.

This can easily happen if you're using addslashes() before inserting form data into the database. This is because PHP implicitly escapes all form data.

Of course I could be completely missing the question :). If so, what exactly are you expecting htmlentities() to do and what does it appear to be doing wrong?
 

Telematx

Ars Tribunus Militum
2,841
http://www.php.net/manual/en/function.htmlspecialchars.php

htmlspecialchars -- Convert special characters to HTML entities
Description

string htmlspecialchars (string string [, int quote_style [, string charset]])

[...]

The optional second argument, quote_style, tells the function what to do with single and double quote characters. The default mode, ENT_COMPAT, is the backwards compatible mode which only translates the double-quote character and leaves the single-quote untranslated. If ENT_QUOTES is set, both single and double quotes are translated and if ENT_NOQUOTES is set neither single nor double quotes are translated.

[FONT=courier,courier new]$description = htmlspecialchars($row[9], ENT_QUOTES);[/FONT]

(I think)
 
Status
Not open for further replies.