Entry
Is their a way, in PHP, to strip-out the content of a web page of bad JavaScript? ex. Javascript that open a new window when you juste closed one.
Feb 19th, 2008 22:06
dman, Jonathan Sharp, Stephane Cote, http://www.ttnr.org
It depends on how your retrieving a web page. PHP is a server side
scripting language which means PHP runs on a web server to build web
pages. It's not a client side scripting language such as JavaScript.
What you're talking about is having PHP be a parser before a web page
get's viewed in your browser. It's possible if you run a HTTP server
with PHP on your local box.
If you had a PHP script that printed a text box on the first screen
where you entered a URL and had the PHP script then go and fetch that
URL and parse the contents of the page for whatever javascript you
wanted to avoid and did a eregi_replace() on it, then it is possible to
have PHP remove javascript. But I don't believe that this solution is
what you're thinking of. There are alot of other factors you need to
take into consideration such as making sure you have absolute urls to
src attributes etc, replacing HREF's so they point back to the PHP
script that "browses" for you...
If you want it to be self contained and local, you can load a HTTP
server and PHP on your local machine and use that to browse the net.