php实用的函数(1)

//返回字符串中的所有单词 $distinct=true 去除重复

function split_en_str($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];  
}

------------------------------------------------------------------

//将HTML表格的每行每列转为数组,采集表格数据

function get_td_array($table) {  
       $table = preg_replace("'<table[^>]*?>'si","",$table);  
       $table = preg_replace("'<tr[^>]*?>'si","",$table);  
       $table = preg_replace("'<td[^>]*?>'si","",$table);  
       $table = str_replace("</tr>","{tr}",$table);  
       $table = str_replace("</td>","{td}",$table);  
       //去掉 HTML 标记  
       $table = preg_replace("'<[\/\!]*?[^<>]*?>'si","",$table);  
       //去掉空白字符    
       $table = preg_replace("'([\r\n])[\s]+'","",$table);  
       $table = str_replace(" ","",$table);  
       $table = str_replace(" ","",$table);  

       $table = explode('{tr}', $table);  
       array_pop($table);  
       foreach ($table as $key=>$tr) {  
               $td = explode('{td}', $tr);  
               array_pop($td);  
           $td_array[] = $td;  
       }  
       return $td_array;  
}

-------------------------------------------------------------

//获取所有链接

function get_all_url($code){  
       preg_match_all('/<a\s+href=["|\']?([^>"\' ]+)["|\']?\s*[^>]*>([^>]+)<\/a>/i',$code,$arr);  
       return array('name'=>$arr[2],'url'=>$arr[1]);  
}

---------------------------------------------------------

//清除HTML标记

function ClearHtml($str){  
       $str = str_replace('<','<',$str);  
       $str = str_replace('>','>',$str);  
       return $str;  
}


-------------------------------------------------------------

/去除HTML标记

function Text2Html($txt){  
       $txt = str_replace("  "," ",$txt);  
       $txt = str_replace("<","<",$txt);  
       $txt = str_replace(">",">",$txt);  
       $txt = preg_replace("/[\r\n]{1,}/isU","  
\r\n",$txt);  
       return $txt;  
}

----------------------------------------------

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论