Last active
January 30, 2016 15:05
-
-
Save softsolution/38f62eb334a8e5d016c8 to your computer and use it in GitHub Desktop.
Функции используемые при парсинге
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* functions for cleaning: | |
replaceLinks(); | |
deleteClasses(); | |
deleteDataAttr(); | |
deleteOther(); | |
full_trim(); | |
*/ | |
function replaceClasses($patterns, $replace, $str){ | |
$str = str_replace($patterns, $replace, $str); | |
return $str; | |
} | |
function replaceLinksBank($str){ | |
$patterns = "/<a\s.*?>(.*?)<\/a>/is"; | |
$replace = '<a class="bank-link" href="#">\\1</a>'; | |
$str = preg_replace($patterns, $replace, $str); | |
return $str; | |
} | |
function replaceLinks($str){ | |
$patterns = "/<a\s.*?>(.*?)<\/a>/is"; | |
$replace = "\\1"; | |
$str = preg_replace($patterns, $replace, $str); | |
return $str; | |
} | |
function deleteClasses($str){ | |
$patterns = '/(class=").*?"/is'; | |
$replace = ""; | |
$str = preg_replace($patterns, $replace, $str); | |
return $str; | |
} | |
function deleteOther($str){ | |
$patterns = array('/<i.*?><\/i>/is', '/<(.*?)\s*?>/is', '/class=\"\"/is'); | |
$replace = array ("", "<\\1>", ""); | |
$str = preg_replace($patterns, $replace, $str); | |
return $str; | |
} | |
function deleteDataAttr($str){ | |
$patterns = array('/data([^\s]*)="(.*?)"/is', '/data\-([^\s].*?)>/is'); | |
$replace = array ("", ">"); | |
$str = preg_replace($patterns, $replace, $str); | |
return $str; | |
} | |
function full_trim($str) { | |
return trim(preg_replace('/\s{2,}/', ' ', $str)); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment