0

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>';

4
  • What you've done is fine. Sure there are different ways to achieve the same output but if your above code is easy to read for you, then no need to change it. Commented Jan 20, 2011 at 23:47
  • <strong><?=$row->title?></strong> Commented Jan 20, 2011 at 23:52
  • @Andrew: And watch your code fall to pieces if it's ever used on a server with shorttags=FALSE Commented Jan 21, 2011 at 0:04
  • Oh, don't be dramatic. He could test that one line, if it doesn't work, no big deal. Commented Jan 21, 2011 at 3:45

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

you can also do this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.