Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- preg_match_all('/<a.*?href="((?:http|https):\/\/vnexpress\.net\/(?:.*?)\/.*?([^\/]*?)\/(?!index)([^\/]*?.html))".*?>.*?<\/a>/m', $content, $matches);
- if($matches)
- {
- $arrReplace = array();
- $arrMapsPrefixs = array(
- 'suc-khoe' => 'longform',
- 'giai-tri' => 'longform',
- 'kinh-doanh' => 'longform',
- 'the-thao' => 'longform',
- 'gia-dinh' => 'longform',
- 'doi-song' => 'longform',
- 'so-hoa' => 'longform',
- 'du-lich' => 'longform'
- );
- foreach($matches[2] as $i => $prefixs)
- {
- $arrReplace[$i] = 'https://vnexpress.net/'.(isset($arrMapsPrefixs[$prefixs]) ? $arrMapsPrefixs[$prefixs] : $prefixs).'/'.$matches[3][$i];
- }
- $content = str_replace($matches[1], $arrReplace, $content);
- }
- preg_match_all('/<a.*?href="((?:http|https):\/\/(suckhoe|giaitri|kinhdoanh|thethao|giadinh|doisong|sohoa|dulich)\.vnexpress\.net\/.*?([^\/]*?.html))".*?>.*?<\/a>/m', $content, $matches);
- if($matches)
- {
- $arrReplace = array();
- $arrMapsPrefixs = array(
- 'suckhoe' => 'suc-khoe',
- 'giaitri' => 'giai-tri',
- 'kinhdoanh' => 'kinh-doanh',
- 'thethao' => 'the-thao',
- 'giadinh' => 'doi-song',
- 'doisong' => 'doi-song',
- 'sohoa' => 'so-hoa',
- 'dulich' => 'du-lich'
- );
- foreach($matches[2] as $i => $prefixs)
- {
- $arrReplace[$i] = 'https://vnexpress.net/'.$arrMapsPrefixs[$prefixs].'/'.$matches[3][$i];
- }
- $content = str_replace($matches[1], $arrReplace, $content);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement