correct javascript + php syntax, easy

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,


Who is Participating?
BraveBrainConnect With a Mentor Commented:
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.
The other is:


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

DJ_AM_JuiceboxAuthor Commented:
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?

DJ_AM_JuiceboxAuthor Commented:
actually if i put the echo statements before that

      return <<<EOD

line, everything works as expected. What is it!

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 ;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.