I would like to know the correct way to use htmlspecialchars()
I have been reading about it and looking at what examples I can find but I guess its just not registering because I have not been able to apply it my self in my own working example.
Could someone show me how to implement htmlspecialchars() and any other appropriate configuration to make this statement secure and what would be considered professional.
<h3>Recent Post</h3>
<?php
$stmt = $con->query('SELECT * FROM blogData ORDER BY id DESC');
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$title = $row['title'];
$content = $row['content'];
$category = $row['category'];
?>
<div class="features">
<div class="box"><img src="Developer/common-files/icons/time@2x.png" width="100" height="100" alt="Wuno Inc.">
<h6><?php echo $category; ?> - <?php echo $title; ?></h6>
<p><?php echo $content; ?></p>
</div>
</div>
<?php
}
?>
</div>
Is this how it should be done? Or what more could I do to this.
<h3>Recent Post</h3>
<?php
$stmt = $con->query('SELECT * FROM blogData ORDER BY id DESC');
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$title = $row['title'];
$content = $row['content'];
$category = $row['category'];
?>
<div class="features">
<div class="box"><img src="Developer/common-files/icons/time@2x.png" width="100" height="100" alt="Wuno Inc.">
<h6><?php echo htmlspecialchars($category); ?> - <?php echo htmlspecialchars($title); ?></h6>
<p><?php echo htmlspecialchars($content); ?></p>
</div>
</div>
<?php
}
?>