i’m calling the htmlspecialchars function inside another function in a class, but when i do this, even though the data displays, it removes all formatting showing the data in a single line.
this is the code:
class Name {
. .. .
public function h($s)
{
echo htmlspecialchars($s, ENT_QUOTES);
}
public function formatQuotes($row)
{
return "<p id=\"ab_quotes\">" . this->h($row['cQuotes']) . "</p>"
. "<p id=\"ab_author\">" . this->h($row['vAuthor']) . "</p>";
}
}
if i remove the reference to htmlspecialchars function, it displays the data as it should.
UPDATE:
this is the css which i’ve applied:
p#ab_quotes{
font-size: 22px;
word-wrap: break-word;
position: absolute;
top: 80px;
left: 5px;
padding: 8px 6px;
}
p#ab_author {
font-size: 15px;
position: absolute;
top: 200px;
right: 5px;
padding: 8px 6px;
text-transform: uppercase;
letter-spacing: 0.1em;
color: #EB3B55;
}
there is no html within $row[‘cQuotes’] and Author variables. it is the css formatting which is removed when the htmlspecialchars is implemented.
another thing, that i noticed was that if i removed ENT_QUOTES, it works, but again with it, it removes the formatting. why is this so?
The problem might be that the function
h()needs to return the data rather than echo it (based on how you are using the result ofh())