1

All I want to do is echo out a PHP variable inside a <li> tag. Refer to the code below. What's the proper format? Mine is not working.

$row['cat_title'];

echo "<li> {$cat_title} </li>";
Don't Panic
  • 41,125
  • 10
  • 61
  • 80
  • 1
    Are you using a template engine (e.g. smarty) ? – GreensterRox Aug 10 '16 at 16:24
  • 1
    Templating would be the way to go IMO, in addition to the `echo`-based answers, you could also use `(s)printf('
  • %s
  • ', $row['cat_title']);`. Your use of `$row` does worry me: it's indicative of your mixing in markup (templating/view related code) with DB related code. That's considered bad practice – Elias Van Ootegem Aug 10 '16 at 16:50
  • 2
    PHP **is** a templating engine. Including an entire 3rd party templating engine to accomplish simple string concatenation/interpolation is ridiculous. If this is in a template/view, use `
  • = $cat_title ?>
  • `, otherwise use `'
  • ' . $cat_title . '
  • '`. – user229044 Aug 10 '16 at 19:08