在網上google了一陣,發現要把通過fckeditor插入文章中的圖片取出來,網上寫的都很麻煩,自己仔細研究了一下午,正則才剛剛開始學,寫了下面這個函數,肯定還有很多不足,請各位指點一二。
- /**
- * 獲取文章圖片,能夠獲取fckeditor插入的圖片
- * @param int $aid 文章ID
- * @return array $imagename 圖片名稱
- **/
- function get_image_article ($aid) {
- global $db,$dbpre;
- $aid = intval($aid);
- $data = array();
- $sql = "select aid,acontent from {$dbpre}article where `aid`='{$aid}'";
- $data = $db->get_one_record($sql);//此處是獲取一行記錄的函數
- $imagename = array();
- preg_match_all('/input type="image" (.*) />/',$data,$arr);
- foreach ($arr as $key => $val) {
- if ($key == 1) {
- foreach ($val as $k => $v) {
- $imagename[] = substr($v,strrpos($v,"/")+1,-1);
- }
- }
- }
- unset ($aid,$data,$sql,$arr);
- return $imagename;
- }
新聞熱點
疑難解答