Re: Use PHP var in PHP generated Javascript?
- From: Max <max@xxxxxxxxxxx>
- Date: Thu, 1 Jan 2009 16:03:32 -0800 (PST)
On Jan 1, 5:36 pm, Bill H <b...@xxxxxxxxx> wrote:
On Jan 1, 6:03 pm, Max <m...@xxxxxxxxxxx> wrote:
I know the common way of using a PHP variable in javascript via:
<script>myjsvar = <?echo $phpvar;?>;</script>
But in my case I'm generating several javascript code blocks (which
produce some flash) via a PHP loop, so I need to figure out another
way to get the PHP vars into these blocks similar to:
foreach ($lines as $line) {
print "<script>myjsvar = $phpvar;</script>";
}
I've tried various ways to get this working included ".$phpvar." and "+
$phpvar+", etc. None seem to work. There has to be a way to make this
work.
Any suggestions?
Thanks,
Max
Wouldn't
print "<script>myjsvar = {$phpvar};</script>";
Work? (note curly braces)
Bill H
Bill, thanks for the reply. I just tested your suggestion and it did
not work. However, after posting I started doing some more experiments
and found the solution (this always happens). Here it is:
print "<script>var mysymbol='".$symbol."';</script>
This works great!
Max
.
- Follow-Ups:
- Re: Use PHP var in PHP generated Javascript?
- From: Jerry Stuckle
- Re: Use PHP var in PHP generated Javascript?
- References:
- Use PHP var in PHP generated Javascript?
- From: Max
- Re: Use PHP var in PHP generated Javascript?
- From: Bill H
- Use PHP var in PHP generated Javascript?
- Prev by Date: Re: How to use HTTPS with PHP
- Next by Date: Re: Using uft8 encoded strings in windows filesystem
- Previous by thread: Re: Use PHP var in PHP generated Javascript?
- Next by thread: Re: Use PHP var in PHP generated Javascript?
- Index(es):
Relevant Pages
|