I was told that I need to use a server-side language to get the source code of a web site. I figure since I have a little experience with PHP, and it’s a server-side language, I might as well ask here first. What I want to do is fairly simple to understand. I want to grab the source code of a website, store it in a JavaScript variable, and split it to get certain information. I already have the split part down, now I just need to get the source code into a JavaScript variable. I’ve tried this:
var sourcecode = <?PHP $sourcecode = htmlspecialchars(file_get_contents(‘url’));
echo $sourcecode ?>
But it didn’t work. I also tried making a PHP script outside of the JavaScript, and then calling the variable directly (I figured this wouldn’t work. It was kind of a last try kind of thing):
var sourcecode = $sourcecode
And, not surprisingly, it still didn’t work.
So, my question is, how can I grab the source code of any web page with PHP, and then pass that source code into a JavaScript variable as a string?
(sorry if all that is over-explained ^_^)