正文

織夢DedeCMS文章內(nèi)容圖片自動添加alt標簽

文章內(nèi)容頁文章內(nèi)容標簽

{dede:field.body/}

改成

{dede:field.body runphp=yes}
global $dsql,$id,$aid;
$myid = isset($id) ? $id : $aid;
$row = $dsql->GetOne("SELECT title FROM `dede_archives` WHERE id=$myid");
$title = $row['title'];
$str = @me;
$search = '/(<img.*?)alt=(["'])?.*?(?(2)|s)([^>]+>)/is';
$search1 = '/(<img.*?)title=(["'])?.*?(?(2)|s)([^>]+>)/is';
$content = preg_replace($search,'$1$3',$str);
$content = preg_replace($search1,'$1$3',$content);
@me = str_replace('<img', "<img alt='{$title}' title='{$title}'", $content);
{/dede:field.body}
聲明:月季網(wǎng)致力月季產(chǎn)業(yè),部分文字和圖片來源網(wǎng)絡(luò),版權(quán)歸原作者,如有侵權(quán)請聯(lián)系刪除。

月季網(wǎng)

月季網(wǎng)