在HTML select中执行PHP代码

I'd like to do something like this :

 <select name="cities">
 <option value="<?php=$row['city']?>"><?php=$row['city']?></option>
 </select>

But the previous code doesn't work.

Does somebody know how to fix this ?

<option value="<?php echo $row['city']; ?>">
  <?php echo $row['city']; ?>
</option>

You have to echo it out ;)

This is not possible:

<?php=$row['city']?>

I guess you mean:

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

See: Escaping from HTMLDocs

If you want to use this:

<?= $row['city'] ?>

Get PHP 5.4 or enable short_open_tagIni in your php.ini.

I think you mean either <?= $variable ?> or <?php echo $variable; ?>. You can't combine the two.

I think it's the <?php=.

Either try <?php echo $row['city'] ?> or <?= $row['city'] ?>.

The second version is the shorthand which is not always enabled and therefore there's no guarantee that it's going to work.

there is no such thing as <?php= [...] ?>
use <?php echo [...] ?> or <?= [...] ?> instead. I personally prefer the first.