Reputation: 36839
I have a weird scenario, I just cant get the
tags removed from a string in PHP.
Here's what happens, I'm pulling out the data from the database with encoding ASCII
The the string looks like this
<p>Blue Power Waterproof</p>
Now I do the following to decode the entities
html_entity_decode($p->description)
with the following results <p>Blue Power Waterproof</p>
I need to remove the
tags but the following is not working
strip_tags(html_entity_decode($p->description))
and removeParagraphTags(html_entity_decode($p->description);
function removeParagraphTags($html){
$pattern = "'#<p[^>]*>(\s| ?)*</p>#'";
iconv(mb_detect_encoding($html, "auto"), 'UTF-8', $html);
return preg_replace($pattern, '', $html);
}
Upvotes: 0
Views: 1771
Reputation: 36839
I solved this problem by getting all descriptions from the database that were stored with HTML entities, decoded the entities so that the entities are converted to html, and then updated each record with the html and not with the entity, this fixed the problem
$sql = "SELECT * FROM products";
$result= pg_query($conn,$sql);
while ($row = pg_fetch_array($result,null,PGSQL_ASSOC)) {
$name = html_entity_decode($row['name']);
$name = iconv('UTF-8', 'ASCII', $name);
$desc = html_entity_decode($row['description']);
$desc = iconv('UTF-8', 'ASCII', $desc);
$ldesc = html_entity_decode($row['longDescription']);
$ldesc = iconv('UTF-8', 'ASCII', $ldesc);
$up = "UPDATE products SET name='".pg_escape_string($name)."',description='". pg_escape_string($desc)."',\"longDescription\"='".pg_escape_string($ldesc)."' WHERE p_id=".$row['p_id'];
pg_query($conn,$up) OR die(pg_last_error());
}
Upvotes: 1