Online Shopping : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to
Did You Find This Entry Useful?

9 of 35 people (26%) answered Yes
Recently 4 of 10 people (40%) answered Yes


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.

Nov 27th, 2008 02:36
healthy man, dman, Jonathan Sharp, Stephane Cote,

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.