1

So basically i have a js file which looks like:

    var player = $("#zen .player");
        
    player.jPlayer({
            ready: function () {
            $(this).jPlayer("setMedia", {
                mp3: ""
            });
        },
        swfPath: "",
        supplied: "mp3"         
    });  

And i want to be able to set the mp3 value of the js from a php value (e.g. $h->post->vars['audio']. So something like mp3: $h->post->vars['audio']

The mp3 value must remain between the double-quotes for some reason in order to work.

I am using Zen Audio Player.

Thanks in advance!

Community
  • 1
  • 1
Manolis
  • 893
  • 1
  • 14
  • 33
  • Dup of [Pass a PHP string to a Javascript variable (including escaping newlines)](http://stackoverflow.com/questions/168214/), and many, *many*, ***MANY*** others. – outis Jan 21 '12 at 17:40

1 Answers1

2

More generally, to put a PHP value in JavaScript:

var something = <?php echo json_encode($php_var); ?>;
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592