This seems like a silly thing, but I have been banging my head against the wall so I thought I'd ask here
I have this code:
<?php
echo '<iframe style="width:<?php echo $width; ?>px;height:100%" src="hike_widget.php?hike_id='.$hike_id.'&height='.$height.'&width='.$width.'" >
</iframe>';
?>
And if I do a view source on that, it shows this:
<iframe style="width:<?php echo $width; ?>px;height:100%" src="hike_widget.php?hike_id=108&height=450&width=450" >
</iframe>
Which is weird because on the same line, the same PHP variable renders correctly, and right next to it in the style snippet, it just renders as text. Any idea 开发者_运维百科why this is happening? Thanks!
This line doesn't make sense:
echo '<iframe style="width:<?php echo $width; ?>px;height:100%" src="hike_widget.php?hike_id='.$hike_id.'&height='.$height.'&width='.$width.'" >
PHP doesn't work that way; you can't nest <?php
tags.
Instead, you should be closing your string and passing $width
to the echo statement. The line should look like this:
<?php
echo '<iframe style="width:', $width, 'px;height:100%" src="hike_widget.php?hike_id=', $hike_id, '&height=', $height, '&width=', $width, '" >';
?>
echo '<iframe style="width:' . $width . 'px;height:100%" src="hike_widget.php?hike_id='.$hike_id.'&height='.$height.'&width='.$width.'" ></iframe>';
精彩评论