0

I am just starting with php programming and I have this question:

Is there any way to set the width and height values of bgStretcher image with variables?

<?php $arrPath=array("bg" => "http://mydomain.com/myimage.jpg"); $w=1500; $h=800; ?>

$(document).ready(function(){
     $(document).bgStretcher({
           images: $arrPath["bg"], imageWidth: $w, imageHeight: $h
     });
});

I'm getting the variable name instead of its values...

Paul Bellora
  • 54,340
  • 18
  • 130
  • 181
Mike
  • 1

2 Answers2

0

Try this:

$(document).ready(function(){
     $(document).bgStretcher({
           images: <?php echo $arrPath["bg"]; ?>, imageWidth: <?php echo $w; ?>, imageHeight: <?php echo $h; ?>
     });
});
Indranil
  • 2,451
  • 1
  • 23
  • 31
  • you're welcome. You should tick your desired answer to mark this question answered. Helps future searchers :) – Indranil Dec 19 '11 at 13:20
0

Additionally to Indranil's answer, another way to write this to save some space is the following:

<?php $arrPath=array("bg" => "http://mydomain.com/myimage.jpg"); $w=1500; $h=800; ?>

$(document).ready(function(){
     $(document).bgStretcher({
           images: <?=$arrPath["bg"]?>, imageWidth: <?=$w?>, imageHeight: <?=$h?>
     });
});
dimme
  • 4,393
  • 4
  • 31
  • 51
  • I'd suggest not to use short tags just to save some space. Also, if you're on a shared server, your host may have switched it off. – Indranil Dec 19 '11 at 14:13