简体   繁体   中英

How to pass php variable into html syntax class name?

How to pass php variable in html syntax,
below code was wrong....

<div class="lid <?=$row["class_name"]?>">
     text
</div>

Try this

<div class="lid <?php echo $row['class_name']; ?>">

Short tags only work by default after version PHP 5.4, and you have to enable shorthand tags for versions before that, in the php settings. <?=?> and <?php echo ?> are the same thing, with short tags enabled, but without them, may not be registered as PHP

Based on the documentation :

echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syntax only works with the short_open_tag configuration setting enabled.

To enable this syntax you can do one of the following

  • set short_open_tag = 1 in your php.ini file
  • add php_value short_open_tag 1 in your .htaccess file

If neither of these are available you will have to use a full php flag with an echo

<?php echo $row['class_name']; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM