开发者

Adding html tags to php echo

开发者 https://www.devze.com 2023-02-05 15:59 出处:网络
Just wondering, what is the correc开发者_开发技巧t way to add HTML <strong> tags or anything else for that matter to this?

Just wondering, what is the correc开发者_开发技巧t way to add HTML <strong> tags or anything else for that matter to this?

echo $row->title

I did this

echo '<strong>'.$row->title.'</strong>';


The way you are doing it is perfectly fine. However, don't forget that you might need to escape html characters unless HTML should be allowed (which is unlikely in a "title").

echo '<strong>'.htmlspecialchars($row->title).'</strong>';

This would escape <> and some other special characters.


There is no wrong or correct way to do it. Do it like it is best readable for you (and this is a subjective question). But try to develop a standard and don't do it in a different way everytime.


you can also do this

echo "<strong>{$row->title}</strong>";
0

精彩评论

暂无评论...
验证码 换一张
取 消