// 建立白名單 require_once('../class/htmlpurifier/HTMLPurifier.auto.php'); $config = HTMLPurifier_Config::createDefault(); $config->set('HTML', 'Allowed', ' ,area[accesskey|alt, coords|href|name|shape|tabindex|target] ,img[alt|border|height|ismap|src|usemap|width] ,b,blockquote[cite],br,dd,dl,dt,em,h1,h2,h3,h4,h5,h6 ,hr,i,li[value],map,ol[start|type] ,nav[accesskey|contenteditable|contextmenu|data-*|draggable|dropzone|hidden|spellcheck|tabindex|translate] ,ol[start|type],p,pre,rp,rt,ruby,s,small,source,strike,strong,style,sub,sup, ,table[border|cols|summary|cellpadding|cellspacing|align] ,tbody[valign],td[bordercolor|colspan|rowspan],tfoot[valign] ,th[colspan|rowspan|scope],thead[valign],tr[colspan|rowspan] ,tt,u,ul,video[autoplay|controls|height|loop|muted|poster|preload|src|width] ,div[style|class|id] ,span[style|class|id] ' ); $purifier = new HTMLPurifier($config); $rs['description'] = $purifier->purify($rs['description']); // 判斷連結圖片是否存在,如果不存在將他移除 preg_match_all("//", $rs['description'], $img_arr); if ($img_arr) { foreach($img_arr[1] as $key=>$img) { $size_arr = getimagesize($img); if (!$size_arr) { $img_arr[0][$key]; $rs['description'] = str_replace($img_arr[0][$key], '', $rs['description']); } } }
2018年6月29日 星期五
【PHP】判斷連結圖片是否存在,如果不存在將他移除
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言