Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的Preg Match获取组合脚本和HTML标记之间的文本_Php_Regex_Wordpress_Parsing_Preg Match - Fatal编程技术网

PHP中的Preg Match获取组合脚本和HTML标记之间的文本

PHP中的Preg Match获取组合脚本和HTML标记之间的文本,php,regex,wordpress,parsing,preg-match,Php,Regex,Wordpress,Parsing,Preg Match,在WordPress/PHP安装中,我需要从Google DFP广告服务器提供的文本广告中检索一个数据值,该数据值由小写和大写字母、数字组成,有时还包含连字符(即11位YouTube视频id)。下面是输出示例。在本例中,我描述了以下数据值位置: I-NEED-THIS-1: This data value is optional and available only when I add it to the ad in Google DFP. I-NEED-THIS-2: This dat

在WordPress/PHP安装中,我需要从Google DFP广告服务器提供的文本广告中检索一个数据值,该数据值由小写和大写字母、数字组成,有时还包含连字符(即11位YouTube视频id)。下面是输出示例。在本例中,我描述了以下数据值位置:

I-NEED-THIS-1:  This data value is optional and available only when I add it to the ad in Google DFP.

I-NEED-THIS-2:  This data value is required when I create the ad in Google DFP and is the most reliable to always be available.

I-NEED-THIS-3:  This data value is optional and available only when I add it to the ad in Google DFP.
Google DFP输出示例:

<div class="a-single a-x">
<div id="div-gpt-ad-xxxxxxxxxxxxx-0">
<script>

    googletag.cmd.push(function() { googletag.display('div-gpt-ad-xxxxxxxxxxxxx-0'); });
</script>
<div id="google_ads_iframe_/xxxxxxxx/AD-NAME_0__container__" style="border: 0pt none;">
    <iframe id="google_ads_iframe_/xxxxxxxx/AD-NAME_0">
    </iframe>
</div>
#document
<html>
    <head>
    <script>var xxxxxxx=true;</script>
    </head>
    <body marginwidth="0" marginheight="0">
        <a href="https://adclick.g.doubleclick.net/aclk....." title="I-NEED-THIS-1" target="_blank">
            <span style="color:cccccc">
                <b>I-NEED-THIS-2</b>
            </span>
        </a>
        <span style="color:black">I-NEED-THIS-3</span>
        <br>
        <script type="text/javascript"></script>
    </body>
</html>
</div>
</div>

googletag.cmd.push(函数(){googletag.display('div-gpt-ad-xxxxxxxx-0');});
#文件
var xxxxxxx=真;
我需要这个

我尝试使用preg_match表达式的一个版本,如下所述:

preg_match(“(*?”)si“,$source,$match);
结果将“…googletag.cmd.push(function()…”脚本输出到“}”。它似乎不想通过此脚本找到模式

我尝试过其他不同的模式,例如:

'#<a.+?title="([a-zA-Z0-9_-]{11})[^"]*"[^>]+?>[\S\s]+?</a>#i'

"'<div><div><script><div><iframe><html><body><a><span><b>(.*?)</b></span></a></body></html></iframe></div></script></div></div>'si"
'#
我已经尝试使用一个版本的preg_match表达式
:

preg_match(“(*?”)si“,$source,$match);
您忘记在
之前和
之后添加空格。Cf:

preg_match("'<span style=\"color:cccccc\">\s*<b>(.*?)</b>\s*</span>'si", $source, $match);
preg_match(“'\s*(.*?\s*'si)”,$source,$match);

你做得很艰难。通过
DOMDocument
查看html parser.XPath会更好:
preg_match("'<span style=\"color:cccccc\"><b>(.*?)</b></span>'si", $source, $match);
preg_match("'<span style=\"color:cccccc\">\s*<b>(.*?)</b>\s*</span>'si", $source, $match);