Facebook
From Denim Lechwe, 4 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 160
  1. <?php
  2. $domains =  array(
  3.             'shop1.com'=>'11111',  
  4.             'shop2.com'=>'1112',  
  5.         );
  6. $dangerouschars  = array(
  7.   '.'=>'\.',
  8.  
  9. );
  10. function wpso_change_urls( $content ) {
  11.    global $domains,$dangerouschars;
  12.    foreach($domains as $domain=>$id){
  13.       $escapedDomain = str_replace(array_keys($dangerouschars),array_values($dangerouschars), $domain);
  14.  
  15.      if (preg_match_all('/=\s*"(\s*https?:\/\/(www\.)?'.$escapedDomain.'[^"]+)\s*"\s+/mi', $content, $matches)){
  16.         // $matches[0] - ="https://example.com"
  17.         // $matches[1] - https://example.com
  18.         for($i = 0; $i<count($matches[0]); $i++){
  19.                 $matchedUrl = $matches[1][$i];
  20.                 $url = rawurlencode($matchedUrl);
  21.                 //is very important to replace with ="..."
  22.                 $content = str_replace($matches[0][$i], "=\"https://www.network-x.com/click/{$id}lorem_lorem={$url}\" ", $content);
  23.         }
  24.      }
  25.    }
  26.    return $content;
  27. }
  28.  
  29. var_dump(wpso_change_urls('href="https://shop1.com/123" asdasd"""dasdasd<><> href="https://shop2.com/345" '));
captcha