#native_company# #native_desc#

Display PHP generated content on Non-PHP pages

By chris
on May 26, 2003

Ever wanted to get some database content or server side scripting output onto
a plain old HTML (non-php) page?

I wrote a link database script in PHP that I wanted to share with other web
sites. But most of these web sites were written in HTML, not PHP. I discovered
that I could call a PHP file using JavaScript to display my database of links
on other peoples web sites.

All that is required is that your PHP script be on a server running PHP and
that the output of the PHP script be valid JavaScript.

Anyone who wanted to use my database
of links just needed to place this script in their HTML where they wanted to
display the content:

<script language="JavaScript" type="text/javascript" src="" target="_blank" target="_new">http://mydomain.com/scripts/db_links.php"></script>

My PHP script looked something like this:

function get_links(){

// get data from database

// store formatted data into a variable
$content.= ....


<!-- Hide from non JS enabled browsers
// Use JavaScript to write content to
document.write('<?PHP echo $content; ?>');
//--> End Hide

That was it. I was surprised at how easy it was.

Hope it helps someone else.