Reputation: 2609
I insert some text contain [
(only one parentheses, not include ]
), then when I use mysql query to the front php page, the [
will damage html css format.
$result = mysql_query("SELECT * FROM mytable Order By date DESC LIMIT 10");
while ($row = mysql_fetch_array($result))
{
echo '<div class="text">'.$row['content'].'</div>';
}
I notice the html output source code.
before the [
text, the html is correct,
<div class="text">this is a test, no parentheses</div>
but after [
text, the html looks as
<div class=”text”>this is a test, contain [ </div>
How many symbols will cause the faults like this? and how to avoid? Thanks.
Upvotes: 0
Views: 147
Reputation: 4984
I notice that your div class is being displayed ”text𔄤
in your second example.
”
is the html entity code for quotation mark. If your css is broken, I'd guess it's because the browser isn't interpreting your class declaration as "text"
and therefor isn't applying the rules. Maybe it isn't the [
, but some other factor that is replacing your quotation marks with the html entity that's breaking your css.
Upvotes: 0
Reputation: 3156
As robertpitt said, character [ as tag inner text value should not damage html. You have to check for something else.
Upvotes: 0
Reputation: 51150
Are you using htmlentities
or htmlspecialchars
anywhere? As a sidenote, you should probably be doing something like this as well:
echo '<div class="text">'.htmlspecialchars($row['content'], ENT_QUOTES).'</div>';
Upvotes: 3