Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1. preg_match_all('/<a.*?href="((?:http|https):\/\/vnexpress\.net\/(?:.*?)\/.*?([^\/]*?)\/(?!index)([^\/]*?.html))".*?>.*?<\/a>/m', $content, $matches);
  2.         if($matches)
  3.         {
  4.             $arrReplace = array();
  5.             $arrMapsPrefixs = array(
  6.                 'suc-khoe' => 'longform',
  7.                 'giai-tri' => 'longform',
  8.                 'kinh-doanh' => 'longform',
  9.                 'the-thao' => 'longform',
  10.                 'gia-dinh' => 'longform',
  11.                 'doi-song' => 'longform',
  12.                 'so-hoa' => 'longform',
  13.                 'du-lich' => 'longform'
  14.             );
  15.             foreach($matches[2] as $i => $prefixs)
  16.             {
  17.                 $arrReplace[$i] = 'https://vnexpress.net/'.(isset($arrMapsPrefixs[$prefixs]) ? $arrMapsPrefixs[$prefixs] : $prefixs).'/'.$matches[3][$i];
  18.             }
  19.             $content = str_replace($matches[1], $arrReplace, $content);
  20.         }
  21.         preg_match_all('/<a.*?href="((?:http|https):\/\/(suckhoe|giaitri|kinhdoanh|thethao|giadinh|doisong|sohoa|dulich)\.vnexpress\.net\/.*?([^\/]*?.html))".*?>.*?<\/a>/m', $content, $matches);
  22.         if($matches)
  23.         {
  24.             $arrReplace = array();
  25.             $arrMapsPrefixs = array(
  26.                 'suckhoe' => 'suc-khoe',
  27.                 'giaitri' => 'giai-tri',
  28.                 'kinhdoanh' => 'kinh-doanh',
  29.                 'thethao' => 'the-thao',
  30.                 'giadinh' => 'doi-song',
  31.                 'doisong' => 'doi-song',
  32.                 'sohoa' => 'so-hoa',
  33.                 'dulich' => 'du-lich'
  34.             );
  35.             foreach($matches[2] as $i => $prefixs)
  36.             {
  37.                 $arrReplace[$i] = 'https://vnexpress.net/'.$arrMapsPrefixs[$prefixs].'/'.$matches[3][$i];
  38.             }
  39.             $content = str_replace($matches[1], $arrReplace, $content);
  40.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement