SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast VKX's Avatar
    Join Date
    Oct 2005
    Location
    Chicago
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using PHP to put a variable in Javascript?

    I have a little javascript application to play music. It looks like this.

    Code:
    <script language="JavaScript" src="http://www.fakedomain.com/myname/audio/audio-player.js"></script>
    <object type="application/x-shockwave-flash" data="http://www.fakedomain.com/myname/audio/player.swf" id="audioplayer1" height="24" width="290">
    <param name="movie" value="http://www.fakedomain.com/myname/audio/player.swf">
    <param name="FlashVars" value="playerID=1&amp;soundFile=podcast.mp3">
    <param name="quality" value="high">
    <param name="menu" value="false">
    <param name="wmode" value="transparent">
    </object>
    The rest of my site operates in php. I would like to replace "podcast.mp3" with a php variable $url. I'm at a loss for how to do that. Can anyone help?
    AwesomeStart.com - Free customizable start pages!

  2. #2
    SitePoint Zealot loathsome's Avatar
    Join Date
    Jul 2008
    Location
    Norway
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
    <param name="FlashVars" value="playerID=1&amp;soundFile=<?php echo $url; ?>">
    Time you enjoy wasting is not wasted time.

    Loathsome Systems

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,158
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Maybe something like
    PHP Code:
    .... src="<?php echo $var?>" ...
    EDIT: what loathsome said.

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure to escape strings correctly:
    PHP Code:
    <param name="FlashVars" value="playerID=1&amp;soundFile=<?php echo htmlspecialchars(rawurlencode($url)); ?>">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •