CyberJunkie
CyberJunkie

Reputation: 22674

Adding html tags to php echo

Just wondering, what is the correct 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>';

Upvotes: 0

Views: 9989

Answers (3)

bharath
bharath

Reputation: 1233

you can also do this

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

Upvotes: 1

Marko
Marko

Reputation: 512

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.

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318468

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.

Upvotes: 1

Related Questions