Question
Today I wrote a function to get pictures inserted into articles by fckeditor. Please give me some advice.
Solution
I googled online for a while and found that it was very troublesome to take out the pictures inserted into the article through fckeditor. I studied it carefully for an afternoon and just started to learn the regular rules. I wrote the following function, but there must be many shortcomings. , please give me some advice. /**
* Get article pictures, and can get pictures inserted by fckeditor
* @param int $aid article ID
* @return array $imagename Image name
**/
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); //Here is the function to get a row of records
$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;
}
Copy code