[英]Regex - Pattern to Replace a HTML tag with specified attribute value
i'm using PHP and i want to check the following tags: iframe and script 我正在使用PHP,并且想检查以下标签: iframe和脚本
I want that if they contains X value in the src attribute to add a Y class to the tag and change src attribute name to data-src . 我希望如果它们在src属性中包含X值,以将Y类添加到标签并将src属性名称更改为data-src 。
ex. 例如
$blacklist = array("google.com/plus.js", "google.com/drive.js");
$myclass = "blocked";
$html = '<script src="http://google.com/plus.js"></script>';
foreach($blacklist as $black)
{
$html = preg_replace(...);
}
/* now $html must be: "<script data-src="google.com/plus.js" class="blocked"></script> */
Anyone can help me with this Regex operation? 有人可以帮我进行此Regex操作吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.