PHPBuilder - Display PHP generated content on Non-PHP pages

RSS Twitter

Display PHP generated content on Non-PHP pages

by: chris
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">"></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 screen
document.write('<?PHP echo $content; ?>');
//--> End Hide

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

Hope it helps someone else.

Comment and Contribute

Your comment has been submitted and is pending approval.




(Maximum characters: 1200). You have characters left.