我正在使用具有以下配置的HTML Purifier:
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
$config->set('URI.DisableExternalResources', false);
$config->set('Core.RemoveInvalidImg',true);
$config->set('URI.DisableResources', false);
$config->set('HTML.Allowed', 'p[align|style],strong,b,em,table[class|width|cellpadding],td,tr,h3,h4,h5,hr,br,u,ul,ol,li,img[src|width|height|alt|class],iframe[src|width|height|alt|class|frameborder|allowfullscreen],span[class],strike,sup,sub');
$config->set('HTML.SafeIframe', true);
$config->set('URI.SafeIframeRegexp', '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%'); //allow YouTube and Vimeo
$purifier = new HTMLPurifier($config);
当我通过YouTube嵌入代码时:
<iframe width="560" height="315" src="http://www.youtube.com/embed/nS8xiUlYNO0" frameborder="0" allowfullscreen></iframe>
输出(无src)发生以下情况:
<iframe width="560" height="315" src="" frameborder="0"></iframe>
为什么要删除src?
答案 0 :(得分:1)
我将正则表达式更改为:
%(www.youtube.com/embed)%
他们在网站上提供的正则表达似乎不起作用。 Youtube已经转向相关协议&#34; // www.youtube.com/embed/123456"
此外,allowfullscreen
不是HTML Purifier中开箱即用的iframe支持的属性。这可能也会导致问题