dom 内の複数の重複したスクリプトとスタイル タグを置き換えるこのコードを見つけましたが、その使用方法がわかりません。
サイトの構築に drupal 7 を使用しています。
できれば助けてください。
本当にありがとうございました..
phpコード:
function stripDuplicateScripts($text) {
$re = '%
# Match duplicate SCRIPT element having same SRC attribute URL.
( # $1: Everything up to duplicate SCRIPT element.
<script # literal start of script open tag
(?: # Zero or more attributes before SRC.
\s+ # Whitespace required before attribute.
(?!src\b) # Assert this attribute is not "SRC".
[\w\-.:]+ # Non-SRC attribute name.
(?: # Attribute value is optional.
\s*=\s* # Value separated by =, optional ws.
(?: # Group attribute value alternatives.
"[^"]*" # Either a double quoted value,
| \'[^\']*\' # or a single quoted value,
| [\w\-.:]+ # or an unquoted value.
) # End group of value alternatives.
)? # Attribute value is optional.
)* # Zero or more attributes before SRC.
\s+ # Whitespace required before SRC attrib.
src # Required SRC attribute name.
\s*=\s* # Value separated by =, optional ws.
([\'"]) # $2: Attrib value opening quote.
((?:(?!\2).)+) # $3: SRC attribute value (a URL).
\2 # Attrib value closing quote.
(?: # Zero or more attributes after SRC.
\s+ # Whitespace required before attribute.
[\w\-.:]+ # Attribute name.
(?: # Attribute value is optional.
\s*=\s* # Value separated by =, optional ws.
(?: # Group attribute value alternatives.
"[^"]*" # Either a double quoted value,
| \'[^\']*\' # or a single quoted value,
| [\w\-.:]+ # or an unquoted value.
) # End group of value alternatives.
)? # Attribute value is optional.
)* # Zero or more attributes after SRC.
\s* # Optional whitespace before tag close.
> # End of SCRIPT open tag.
</script\s*> # SCRIPT close tag.
.*? # Stuff up to duplicate script element.
) # End $1: Everything up to duplicate SCRIPT.
<script # literal start of script open tag
(?: # Zero or more attributes before SRC.
\s+ # Whitespace required before attribute.
(?!src\b) # Assert this attribute is not "SRC".
[\w\-.:]+ # Non-SRC attribute name.
(?: # Attribute value is optional.
\s*=\s* # Value separated by =, optional ws.
(?: # Group attribute value alternatives.
"[^"]*" # Either a double quoted value,
| \'[^\']*\' # or a single quoted value,
| [\w\-.:]+ # or an unquoted value.
) # End group of value alternatives.
)? # Attribute value is optional.
)* # Zero or more attributes before SRC.
\s+ # Whitespace required before SRC attrib.
src # Required SRC attribute name.
\s*=\s* # Value separated by =, optional ws.
([\'"]) # $4: Attrib value opening quote.
\3 # This script must have duplicate SRC URL.
\4 # Attrib value closing quote.
(?: # Zero or more attributes after SRC.
\s+ # Whitespace required before attribute.
[\w\-.:]+ # Attribute name.
(?: # Attribute value is optional.
\s*=\s* # Value separated by =, optional ws.
(?: # Group attribute value alternatives.
"[^"]*" # Either a double quoted value,
| \'[^\']*\' # or a single quoted value,
| [\w\-.:]+ # or an unquoted value.
) # End group of value alternatives.
)? # Attribute value is optional.
)* # Zero or more attributes after SRC.
\s* # Optional whitespace before tag close.
> # End of SCRIPT open tag.
</script\s*> # SCRIPT close tag.
\s* # Strip whitespace following duplicate.
%six';
while (preg_match($re, $text)) {
$text = preg_replace($re, '$1', $text);
}
return $text;
}