NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP parsing to Javascript questions

webmaster at vbplusme.com webmaster at vbplusme.com
Sat Jul 18 06:24:15 EDT 2009


Hello talk,

Hello and greetings.

I have a standalone javascript that I have customized to do a banner
display and I have a PHP script that loads link information into a
MySQL. The javascript uses these links currently in its display but
the links are manually entered into the javascript data definition,
for example:
[code]

var pausecontent=new Array()
pausecontent[0]='<a href=""/></a>'
pausecontent[1]='<a href=""/></a>'
pausecontent[2]='<a href=""/></a>'
pausecontent[3]='<a href=""/></a>'
pausecontent[4]='<a href=""/></a>'

//the rest of the javascript that processes the array is here

[/code]

I would like to generate this array information in PHP and insert it
into the javascript dynamically. Javascript doesn't have an include
and the ones that I have been able to find are pretty ugly.

I was thinking that I could use a PHP script to dynamically generate
the whole script and storing it or possibly split the javascript into
pieces, generate the array (array.js) part of the script dynamically and store
the run part(main.js) of it with out the array definition then use php to put
them together at run time.    For example ( I haven't tested this yet
so I don't know if it works):

[code]
// contents of allscripts.php
<?php
header("Content-Type: text/javascript");
include "main.js";
include "array.js";
?>
[/code]

// this call would replace the one I am using now
<script type="text/javascript" src="allscripts.php"></script>


The links that populate the array periodically change so I use PHP and
MySQL to track and store the most current versions. I want to be able
to do a query to populate the array and do a seamless merge into the
javascript to do the display.

This all seams pretty kludgy to me so I am open to any suggestions
about how to do it more elegantly.

TIA for any ideas.


-- 
Best regards,





More information about the talk mailing list