I have a minimal PHP script that utilises an open-source PHP Simple HTML DOM Parser. An external script, when called, reads in a webpage and returns it's content to index.php which displays it. The basic example I present below works, but I want to integrate the PHP call into javascript to make it interactive.
index.php
<html>
<head>
<title>php / javascript interaction</title>
</head>
<body>
<?php include 'simple_html_dom_utility.php';?>
<?php include 'webpage_parser.php';?>
<script type="text/javascript">
// this Javascript isn't fully implemented but illustrates the intent..
links = ["http://en.m.wikipedia.org/wiki/Moon", "http://en.m.wikipedia.org/wiki/Star",
"http://en.m.wikipedia.org/wiki/Planet", "http://en.m.wikipedia.org/wiki/Sun"];
k = 0;
window.setInterval(function(){ // rotate through webpages
var newurl = links[ k ];
console.log(newurl);
// call PHP here with 'newurl' argument to append new website's content to the DOM
k = (k+1) % links.length;
}, 5000);
</script>
</body>
</html>
webpage_parser.php
<?php
// this needs to change to accept input arguments for $url
$url = "http://en.m.wikipedia.org/wiki/Sun";
$html = file_get_html($url);
echo $html;
?>
simple_html_dom_utility.php is available here
I can foresee a jQuery solution may be needed to convert php-to-javascript content into DOM elements. For now I'm really just interested in getting php and javascript talking to each other.