Forum Moderators: coopster
Anyway, when I read in my data, I'm doing this:
$row=mysql_fetch_assoc($resultID);
$var = htmlentities(html_entity_decode($row[whatever]));
It seems to work. The question is, how do I do this for ALL the fields in a table? I guess what I want to do is the equivalent of:
$row=htmlentities(html_entity_decode(mysql_fetch_assoc($resultID)));
This of course gives me errors. Is there an easier way? Am I going about things wrong?
You'll follow the TR&O 1522 ...... and more.<p>On the run out to ..<br>On DVD There's some HTML in there, and an & symbol. If I use htmlentities(html_entity_decode()), I lose the <p> and the <br> while fixing the & symbol, no?
My big question here is... Do I store text in a database totally encoded? If not, how do I retrieve paragraphs or line breaks? Should I go through the database and clean everything to one method or another? Any good articles out on this? I did some searching just now and I'm not really finding the right subject matter.
I suggest that you fix everything first!
My preferred method of fixing such a thing is this:
$dh=mysql_query("SELECT `id`,`text` FROM `articles`");
while ($r=mysql_fetch_assoc($dh))
{
// first, break & symbols to avoid &amp;
$r[text]=str_replace("&","&",$r[text]);
// next, break correct entities to avoid &copy; etc.
$r[text]=str_replace("£s;","#",$r[text]);
$r[text]=str_replace("©","©",$r[text]);
...etc...
//now, fix everything, & first:
$r[text]=str_replace("&","&",$r[text]);
$r[text]=str_replace("#","£s;",$r[text]);
$r[text]=str_replace("©","©",$r[text]);
...etc...
mysql_query("UPDATE `articles` SET `text` = '".mysql_real_escape_string($r[text])."' WHERE `id` = $r[id]");
}