?
Solved

correct javascript + php syntax, easy

Posted on 2007-08-09
5
Medium Priority
?
209 Views
Last Modified: 2013-11-05
Hi,
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:
 
    $mainframe->getCfg('live_site')

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,

Thanks

0
Comment
Question by:DJ_AM_Juicebox
  • 2
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
BraveBrain earned 2000 total points
ID: 19663229
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.
0
 
LVL 15

Expert Comment

by:ncoo
ID: 19663400
The other is:

<?php

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

?>
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 19664099
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:

<?php

     .... 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?

Thanks
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 19664158
actually if i put the echo statements before that

      return <<<EOD

line, everything works as expected. What is it!

0
 
LVL 15

Expert Comment

by:ncoo
ID: 19664872
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 ;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

840 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