Mixing JAVA and PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tstimple
Forum Commoner
Posts: 53
Joined: Wed Jan 21, 2004 10:12 pm

Mixing JAVA and PHP

Post 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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

That's javascript, not Java.

Code: Select all

$PSAMID = $_GET['Dealership'];
echo "<script type="text/javascript" src="" . $PSAMID . "HFrames_var.js"></script>";
Last edited by d3ad1ysp0rk on Fri Feb 27, 2004 10:17 pm, edited 1 time in total.
itbegary
Forum Commoner
Posts: 34
Joined: Sun Jan 05, 2003 2:50 am

Post 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.
tstimple
Forum Commoner
Posts: 53
Joined: Wed Jan 21, 2004 10:12 pm

[SOLVED]

Post by tstimple »

Thanks itbegary.
It works great now!
Post Reply