通过php设置img src?

Here is my problem.

If I do:

  $imagePath = "images/spalt_images/body_images/525A.JPG";
              ?>
<img src="<?php $imagePath ?>" alt="front image" class="productImage"/> 
               <?php

Then my image does not show up.

However, if I do:

<img src="images/spalt_images/body_images/525A.JPG" alt="front image" class="productImage"/> 

Then my image shows up just fine. Why would it not work with php?

Thanks

You need to echo it:

<?php echo $imagePath ?>

or use a short tag (not recommended, but that's another discussion):

<?=$imagePath ?>

You need to echo $imagepath otherwise it won't 'print' it out.

Change <?php $imagePath ?> in your code to <?=$imagePath?>, or add an echo if your server doesn't allow shorttags.