收藏PHP常用函數

//將HTML表格的每行每列轉爲數組,採集表格數據
<?
function get_td_array($table) {
        $table = preg_replace("'<table[^>]*?>'si","",$table); //OSPHP.com.CN
        $table = preg_replace("'<tr[^>]*?>'si","",$table);
        $table = preg_replace("'<td[^>]*?>'si","",$table);
        $table = str_replace("</tr>","{tr}",$table);
//OSPHP.com.CN

        $table = str_replace("</td>","{td}",$table);
        //去掉 HTML 標記 
        $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table); //OSPHP.COm.CN
        //去掉空白字符  
        $table = preg_replace("'([rn])[s]+'","",$table);
        $table = str_replace(" ","",$table);
//OSPHP.com.CN


        $table = str_replace(" ","",$table);
        
        $table = explode('{tr}', $table);
        array_pop($table); //開源代碼OSPHP.COM.Cn
        foreach ($table as $key=>$tr) {
                $td = explode('{td}', $tr);
                array_pop($td);
            $td_array[] = $td; //開源代碼OSPhP.COm.CN
        }
        return $td_array;
}

?>


 
//返回字符串中的所有單詞 $distinct=true 去除重複
<?
function split_en_str($str,$distinct=true) {
        preg_match_all('/([a-zA-Z]+)/',$str,$match); //PHP開源代碼
        if ($distinct == true) {
                $match[1] = array_unique($match[1]);
        }
        sort($match[1]);
//OsPHP.COM.CN


        return $match[1];
}
?>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章