SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    External JavaScript and PHP

    How do I create a javascript variable from a php variable using External JavaScript and PH?

    My script so far:

    PHP Code:
    <?php 
    $url 
    "http://localhost";

    header('Content-type: text/javascript');

    echo 
    'var url = <?php echo $url; ?>';

    echo 
    'alert(url);';


    ?>

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Close, but try this instead
    PHP Code:
    $url "http://localhost"
    header('Content-type: text/javascript');
    echo 
    'var url = "' $url '";';
    echo 
    'alert(url);'

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    455
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    php within javascript within php is brand new to me as of today. Who would've thunk?

    Thanks for your help cpradio.


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
  •