PHP后台处理富文本编辑器内容时,为媒体标签的链接加上域名
适用于提交的富文本内容的媒体标签的链接不带域名时
/**
* @notes: 设置内容图片域名
* @param $content
*/
function add_content_domain($content)
{
if(empty($content)){
return '';
}
$imgPreg = '/(<img .*?src=")[^https|^http](.*?)(".*?>)/is';
$videoPreg = '/(<video .*?src=")[^https|^http](.*?)(".*?>)/is';
$audioPreg = '/(<audio .*?src=")[^https|^http](.*?)(".*?>)/is';
$domain = request()->domain();
$content = preg_replace($imgPreg, "\${1}$domain\${2}\${3}", $content);
$content = preg_replace($videoPreg, "\${1}$domain\${2}\${3}", $content);
return preg_replace($audioPreg, "\${1}$domain\${2}\${3}", $content);
}

浙公网安备 33010602011771号