Skip to content

Instantly share code, notes, and snippets.

@Sieboldianus
Created January 31, 2022 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sieboldianus/bfc3300a8e2adf0882143ed352d4c814 to your computer and use it in GitHub Desktop.
Save Sieboldianus/bfc3300a8e2adf0882143ed352d4c814 to your computer and use it in GitHub Desktop.
Stackoverflow as iframe with php file_get_contents();
<!DOCTYPE html><html>
<?php
$url = 'https://stackoverflow.com/questions/5710867/downloading-and-unzipping-a-zip-file-without-writing-to-disk&noredirect=1';
$site = file_get_contents($url);
$site = preg_replace('#<div class="ff-sans ps-fixed z-nav-fixed ws4 sm:w-auto p32 sm:p16 bg-black-750 fc-white bar-lg b16 l16 r16 js-consent-banner">(.*?)</div>#s', ' ', $site);
$site = preg_replace('~<\s*\bscript\b[^>]*>(.*?)<\s*\/\s*script\s*>~is', ' ', $site);
echo $site
?>
</html>
@Sieboldianus
Copy link
Author

I recently had to include an iframe of stackoverflow into an interactive presentation for illustrating purposes. However, stackoverflow contains code and tracking that prevents including any page in an iframe.

Modify the url and upload the above iframe.php to any php capable public server. Reference the new index.php as your iframe, instead of directly linking to stackoverflow.

Note that for security reasons, I added the url as a static parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment