Help Please, Can I do script src=$variable??? (Call Script SRC from PHP variable??)

Discussion in 'JavaScript' started by boon4376, Nov 19, 2010.

  1. #1
    I need to install some tracking pixel code for one of my checkout systems.

    This is the sample code for calling the tracking pixel

    <script src="https://xxxxxx.com/i_third_sale/xxxxxx/406/ORDER_AMOUNT/ORDER_NUMBER/EMAIL_ADDRESS"></script> 
    <noscript><IMG SRC="https://xxxxxx.com/i_sale/xxxxxx/406/ORDER_AMOUNT/ORDER_NUMBER/EMAIL_ADDRESS"></noscript> 
    HTML:
    Now my question is that I would like to dynamically create the data that needs to be in these URL's using PHP. Can I do a <script src="$script_src"></script>... I know PHP doesnt tend to play well with javascripts sometimes so I'm just wondering if this concept will even work.

    Thanks.
     
    boon4376, Nov 19, 2010 IP
  2. webcosmo

    webcosmo Notable Member

    Messages:
    5,840
    Likes Received:
    153
    Best Answers:
    2
    Trophy Points:
    255
    #2
    simply create an element e.g. <div></div> and insert the script from within the php.
     
    webcosmo, Nov 19, 2010 IP
  3. boon4376

    boon4376 Greenhorn

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    can you please provide an example of how that would go?
     
    boon4376, Nov 19, 2010 IP
  4. boon4376

    boon4376 Greenhorn

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    Ok this actually turned out to be super simple...

    Here is the following code which works as needed.

    $script_src = "https://xxxxxx.com/i_third_sale/xxxxxx/406/ORDER_AMOUNT/ORDER_NUMBER/EMAIL_ADDRESS";
    echo <<<html
    <script src="$script_src"></script>
    html;
    PHP:
     
    boon4376, Nov 19, 2010 IP