Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove JS from Print CSS

So I've working on a website and i'm just doing the finishing touches, I've used a lot of javascript on this and it keeps showing within the print version of the site... even if I comment it out, I was just wondering if anyone was aware of a way of removing javascript from the print version of the site easily, and if it's any help, the site is written in PHP.

Thanks for reading.

EDIT: The javascript itself is not running, its directly showing the code itself, rather than running it, and if possible I would like to remove all the javascript elements entirely.

like image 907
Aaron Lee Avatar asked Mar 09 '26 09:03

Aaron Lee


1 Answers

Can you try this PHP code:

$str = file_get_contents("http://stackoverflow.com");
$pattern = '#\<script.*?\>(.*?)\<\/script\>#si'; 
$str = preg_replace($pattern, '', $str);
die($str);

It removes all script tags from inside. Now you can print it...

like image 55
Karol Avatar answered Mar 11 '26 21:03

Karol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!