correct javascript + php syntax, easy

Posted on 2007-08-09
Last Modified: 2013-11-05
I've got a PHP file, and I want to create an include path using a php variable. Right now I have this:

<script type="text/javascript" src="$mainframe->getCfg('live_site')/$tiny_url/$tiny_file"></script>

It almost works, just the part with:

messes up. When the PHP page is generated, it comes out like:

<script type="text/javascript" src="('live_site')/some_path/the_file_name"></script>

I must be missing some quotes or something? I'm a PHP/js novice,


Question by:DJ_AM_Juicebox
    LVL 11

    Accepted Solution

    One approach is:
    <script type="text/javascript" src="<?php echo $mainframe->getCfg('live_site')."/$tiny_url/$tiny_file";?>"></script>

    But it depends how the rest of your code is, i.e. if the script tag is already in quotes etc.
    LVL 15

    Expert Comment

    The other is:


    echo '<script type="text/javascript" src="'.$mainframe->getCfg('live_site').'/'.$tiny_url.'/'.$tiny_file.'"></script>';


    Author Comment

    Hi guys,

    It doesn't seem to be working - my file is indeed a php file, the first line is:

            <? php

    and the php tag is not closed till the end of the file. Now there is a bunch of php code above my line working fine, but then a strange 'return <<<EOD' statement. Kind of looks like:


         .... some ok php stuff ...

          return <<<EOD  

           <!--   An html comment parsed correctly in the generated page!!!   -->

           echo "hello"        // a basic echo call which fails!!!

    I'm not sure what the return <<<EOD statement does, or how the html comment is getting parsed correctly when it is still within the php braces. Anyone have an idea?


    Author Comment

    actually if i put the echo statements before that

          return <<<EOD

    line, everything works as expected. What is it!

    LVL 15

    Expert Comment

    With out seeing all the code it's hard to tell if the return is php or javascript.

    Return returns the product of a function.

    function functionname() {
    value = 1 + 1;
    retrun value;

    return <<<EOD

    looks like bad code maybe it should be:

    return '<<<EOD';

    echo "hello"       // a basic echo call which fails!!!

    it should be

    echo "hello"; //it needs the ;

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to count occurrences of each item in an array.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now