Cet article de vous présenter le contenu parle de PHP couramment utilisé dans la fonction de collecte sommaire (avec code), il y a une certaine valeur de référence, il n’y a que besoin d’amis peut se référer à un peu, j’espère pouvoir vous aider.
Ces jours-ci une attention pour le programme d’acquisition de PHP, pour constater que l’utilisation de PHP pour recueillir le contenu est si commode, la fonction d’acquisition souvent utilisé ici résumée, facile à utiliser par la suite !
Obtenez tous les contenus liés et adresses
function getAllURL($code){preg_match_all('/<a\s+href=["|\']?([^>"\' ]+)["|\']?\s*[^>]*>([^>]+)<\/a>/i',$code,$arr);return array('name'=>$arr[2],'url'=>$arr[1]);}
Obtenez toutes les adresses de photo
function getImgSrc($code){$reg = "/]*src=\"(http:\/\/(.+)\/(.+)\.(jpg|gif|bmp|bnp|png))\"/isU";preg_match_all($reg, $code, $img_array, PREG_PATTERN_ORDER);return $img_array[1];}
L’URL de script actuel
function getSelfURL(){if(!empty($_SERVER["REQUEST_URI"])){$scriptName = $_SERVER["REQUEST_URI"];$nowurl = $scriptName;}else{$scriptName = $_SERVER["PHP_SELF"];if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName;else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];}return $nowurl;}
Convertit le nombre de pleine largeur en un certain nombre de demi-largeur
function getAlabNum($fnum){$nums = array("0","1","2","3","4","5","6","7","8","9");$fnums = "0123456789";for($i=0;$i<=9;$i++) $fnum = str_replace($nums[$i],$fnums[$i],$fnum);$fnum = ereg_replace("[^0-9\.]|^0{1,}","",$fnum);if($fnum=="") $fnum=0;return $fnum;}
Suppression des balises HTML
function text2Html($txt){$txt = str_replace(" "," ",$txt);$txt = str_replace("<","<",$txt);$txt = str_replace(">",">",$txt);$txt = preg_replace("/[\r\n]{1,}/isU","<br/>\r\n",$txt);return $txt;}
Balises HTML clair
function clearHtml($str){$str = str_replace('<','<',$str);$str = str_replace('>','>',$str);return $str;}
Chemin d’accès relatif converti en chemin absolu
function relative2Absolute($content, $feed_url) {preg_match('/(http|https|ftp):\/\//', $feed_url, $protocol);$server_url = preg_replace("/(http|https|ftp|news):\/\//", "", $feed_url);$server_url = preg_replace("/\/.*/", "", $server_url);if ($server_url == '') {return $content;}if (isset($protocol[0])) {$new_content = preg_replace('/href="\//', 'href="'.$protocol[0].$server_url.'/', $content);$new_content = preg_replace('/src="\//', 'src="'.$protocol[0].$server_url.'/', $new_content);} else {$new_content = $content;}return $new_content;}
Obtient le contenu de la balise spécifiée
function getTagData($str, $start, $end){if ( $start == '' || $end == '' ){return;}$str = explode($start, $str);$str = explode($end, $str[1]);return $str[0];}
Convertir chaque ligne d’un tableau HTML dans un tableau de format CSV
Function Gettrarray ($table) {$table = Preg_replace ("' tr B' », ' « ', $table) ; $table = Str_replace ( » < / TD > «, " »,", $table) ; $table = Str_replace (« % », « {tr} », $table) ; //Remove balise HTML $table = preg_replace ("' < [\ / \ !] *? [^ ≪>] * ? > « Si », « », $table) ; //Remove caractère vide $table = Preg_replace ("' ([\r\n]) [\s]+ ' », « », $table) ; $table = Str_replace ( » ",", $Table) ; $table = Str_replace (" », « », $table) ; $table = Explode ( », {tr} », $table) ; Array_pop ($table) ; return $table ;}
Convertir chaque ligne des tables HTML en tableaux et collecter des données tabulaires
Function Gettdarray ($table) {$table = Preg_replace ("' tr B' », « », $table) ; $table = Preg_replace ( » ' ≪ Tr [^ >] * ? > « Si », « », $table) ; $table = Preg_replace ("' » ' « ' ' « si », » «, $table) ; $table = Str_replace (« % », « {Tr} », $table) ; $table = Str_replace (« b », « td {} », $table) ; //Remove balise HTML $table = preg_replace ( » ' ≪ [\ / \ !] *? [^ ≪>] * ? > « Si », « », $table) ; //Remove caractère vide $table = Preg_replace ("' ([\r\n]) [\s]+ ' », « », $table) ; $table = Str_replace ( » », », $Table) ; $table = Str_replace (" », « », $table) ; $table = Explode (« {tr} », $table) ; Array_pop ($table) ; foreach ($table comme $Key = > $tr) {$td = explode (« TD {} », $TR) ; Array_pop ($TD) ; $TD _array [] = $TD ;} $TD retour _array ;}
Renvoie tous les mots d’une chaîne $distinct = vrai supprimer doublons
function splitEnStr($str,$distinct=true) {preg_match_all('/([a-zA-Z]+)/',$str,$match);if ($distinct == true) {$match[1] = array_unique($match[1]);}sort($match[1]);return $match[1];}