Re: why this doesn't work as an external file but does internally?

From: Date: Tue, 05 Oct 2004 20:15:19 +0000
Subject: Re: why this doesn't work as an external file but does internally?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-198721@lists.php.net to get a copy of this message
> Hi guys, > > I have this code Javascript code: > > if (document.images) { > > img1on = new Image(); img1on.src = "<?php echo $base_url; > ?>Graphics/<?php echo $img_home_on; ?>"; > img2on = new Image(); img2on.src = "<?php echo $base_url; > ?>Graphics/<?php echo $img_programdetails_on; ?>"; <snip> > > Regards, > > Aaron > When you mix PHP and javascript together in an external file, the file needs to be PHP and you should include it with PHP. I just recently went through this. I had an external javascript file with some PHP in it. It was originally called into the index.php page as: <script type="text/javascript" src="includes/links.js"> But none of the PHP in the links.js worked. So I renamed the file to links.php and called it in index.php like so: <?php include 'includes/links.php'; ?> And everything worked perfectly. -- --Matthew Sims --<http://killermookie.org>

« previous php.general (#198721) next »