Problem
Today, I wrote a function to retrieve the image inserted by fckeditor.
Solution
After a while on the internet, google found that it was very troublesome to write images inserted in articles through fckeditor. After studying the regular expressions for one afternoon, I just started learning, after writing the following function, you must have many shortcomings. Please give me some advice. /**
* Get the article image and get the picture 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); // The function used to obtain 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