ehime

Untitled

Dec 17th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1.     /** @closure $replaces; status: working */
  2.     $replaces = function ($subject, $patterns, $replaces)
  3.     {
  4.         $patterns = array_values($patterns);
  5.         $replaces = array_values($replaces);
  6.         if (count($patterns) !== count($replaces)) return false;
  7.  
  8.         for ($i=0;$i<count($patterns);$i++)
  9.  
  10.             $subject = preg_replace($patterns[$i], $replaces[$i], $subject);
  11.  
  12.         return $subject;
  13.     };
  14.  
  15.     $cpath = "/website-capture/$cdir/";
  16.  
  17.     // run as closure
  18.     $body = $replaces($body,
  19.         array (
  20.             '~<script\b(?>[^<]++|<(?!/script))*<\/script>(*SKIP)(?!)|\b(?:href|src)\s*=\s*(["\']?+)\K(?:/(?!/)|(?=[\s>]|\1))~i',         # html
  21.            '~\b(?::url)\s*\(\s*(["\']?+)\K(?:/(?!/)|(?=[\s>]|\1))~i',            # css
  22.        ),
  23.         array (
  24.             $cpath,                                                            # /html
  25.            $cpath,                                                            # /css
  26.        )
  27.     );
Advertisement
Add Comment
Please, Sign In to add comment