PDA

View Full Version : can you write javascript inside php?



acc
July 3rd, 2007, 07:23 PM
I'm just starting to learn php, but familiar with asp.

I need to write this script to embed a flash file



<script type="text/javascript">

var fo = new SWFObject("viewer.swf", "viewer", "100%", "100%", "7", "#181818");

fo.addVariable("preloaderColor", "0xffffff");

fo.addVariable("xmlDataPath", "gallery.xml");

fo.write("flashcontent");

</script>



The reason I wish to write this in PHP is that I want the


"gallery.xml"


to be a number that will keep changing depending on what link is selected based on a query from the link


if name.php?id=138 is selected, then the xml file to be used is 138.xml

Is this possible?

senocular
July 3rd, 2007, 07:30 PM
yes. PHP is run prior to the browser receiving the HTML. Just put the PHP in the gallery.xml spot and have it throw in your value. It'd look like what you have but something like:



fo.addVariable("xmlDataPath", "<?= $_GET['id']; ?>.xml");

acc
July 3rd, 2007, 07:50 PM
thanks a lot :)