Page 1 of 1

Mixing JAVA and PHP

Posted: Fri Feb 27, 2004 1:31 pm
by tstimple
OK,
Here's what I'm trying to do...

I am sending a variable called "Dealership" into a php page.
The variable for this example is "AAC[X"
(This variable is used as part of a file name to load a javascript file into that page)

How I want the line to look after php:

Code: Select all

<script type='text/javascript' src='PSAMAACїXHFrames_var.js'></script>
Here is my php code:

Code: Select all

<?php
$PSAMID=$_GET['Dealership'];

$begining="<script type='text/javascript' src=''PSAM";
$middle=$PSAMID;
$end="HFrames_var.js'></script>";
$scriptpath="".$begining." ".$middle." ".$end."";

echo $scriptpath

?>
I also tried:

Code: Select all

<?php
echo "<script type='text/javascript' src=''PSAM".$PSAMID."HFrames_var.js'></script>"

?>
with the mixture of JAVA and PHP, There are just to many single quotes, quotes, hacks, slashes, and dots !
Can someone help me with this syntax???
Thanks,
--Tim

Posted: Fri Feb 27, 2004 1:52 pm
by d3ad1ysp0rk
That's javascript, not Java.

Code: Select all

$PSAMID = $_GET['Dealership'];
echo "<script type="text/javascript" src="" . $PSAMID . "HFrames_var.js"></script>";

Posted: Fri Feb 27, 2004 9:40 pm
by itbegary
Try this:

Code: Select all

<?php

echo "<script type="text/javascript" src='PSAM".$PSAMID."HFrames_var.js'></script>" 


?>
You don't have to escape the single qoutes when it's inside of double qoutes. You can use single quotes in HTML but I choose to use double allowing me to put the single quotes in for the Java/Javascript.

So in PHP you wrap the whole thing in double qoutes (important because single qoutes makes the string literal include escape characters) and then put the included doubles qoutes in as extended characters.

[SOLVED]

Posted: Sat Feb 28, 2004 8:42 pm
by tstimple
Thanks itbegary.
It works great now!