Here, we would simply capture noscript
tags, add an if
statement to ignore those, then we would be retuning our desired output with a simple expression such as:
(<noscript>)[\s\S]+?<\/noscript>|<style(.+?)>(.+?)<\/style>
Test
$re = '/(<noscript>)[\s\S]+?<\/noscript>|<style(.+?)>(.+?)<\/style>/mi';
$str = '<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<style type="text/css"></style>
<noscript><style>
< / style></noscript>
<!-- Twitter Cards Meta by USM STARTS-->
<meta name="twitter:card" content="summary" />
<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
<link rel="pingback" href="/xmlrpc.php">
<noscript><style>
< / style></noscript>
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $key => $value) {
if ($value[1] != '<noscript>') {
echo $value[3];
}
}
Output
.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}