newcomer newcomer - 4 months ago 7
PHP Question

How to output this HTML code in PHP?

<li class="moveUnit">
<a href="javascript:void(0)" title="" class="currentItem">
<img src="$picture[1]" alt="" ref1="$picture[1]" ref2="$picture[1]" onmouseover="Biz.Product.Product.ChangePic(this);" class="Picture40"/>
</a>
</li>


by trying to put this line of code in php file, I found this line has reserved char that will not be allowed in php. Please help, I have tried
htmlspecialchars()
. Still, I don't know why it is not working.

Answer

If this is inside php tags (<?php ?>) it will need to be output using echo(); like so:

<?php
echo '<li class="moveUnit"><a href="javascript:void(0)" title="" class="currentItem"><img src="' . $picture[1] . '" alt="" ref1="' . $picture[1] . '" ref2="' . $picture[1] . '" onmouseover="Biz.Product.Product.ChangePic(this);" class="Picture40"/></a></li>' ;
?>

OR if it's not between, you can echo just those variables between HTML:

<li class="moveUnit"><a href="javascript:void(0)" title="" class="currentItem"><img src="<?php echo $picture[1]; ?>" alt="" ref1="<?php echo $picture[1]; ?>" ref2="<?php echo $picture[1]; ?>" onmouseover="Biz.Product.Product.ChangePic(this);" class="Picture40"/></a></li>