1

我的 html 看起来像这样(它的 javascript 用于 Flash 播放器):

var flashvars =
            {
                'autoplay'          : autoplay,
                'autoreplay'        : 'false',
                'start'             : '',
                'hideLinkPane'      : 'true',
                'disable_sharebar'  : 'true',
                'disablePauseroll'  : disablePauseroll,
                'video_url'         : encodeURIComponent('WQFuk9Py2VC3jsCrPDJ69xtsj33MiXAElBzQw3TSHqOOyDYL0vRJELrB1hTTW3NG0A54kE2FVueuHMkQd8JveYb92eV+dYH4IUrrvJdP5Of9HGi+5i6GT11nL0dAv/ecyP4sB0jM8rVZzyS8imLarvPUvPuFPvvB8nwYXZ2ZKon4IPjmtC8SPftaw0PSuZKMg735hLCraeAE3lMQbRwiY7yMHKmUHDALG1Ky+HBDiK20vAGEIMwzPwKZmhbBXRGiHzEiXiRk4JgaVyp6N66EALao7VOE7UTzJLs='),
                'encrypted'         : 'true',
                'video_title'       : "some cool vids title here",
                'embed_js'          : "",
                'prerollRepeat'     : "false"
            };

如何使用 preg_match 提取 video_title 的值,使其变为:

回声 $videoTitle;

将输出:一些很酷的视频标题在这里

对于 video_url 将输出:

WQFuk9Py2VC3jsCrPDJ69xtsj33MiXAElBzQw3TSHqOOyDYL0vRJELrB1hTTW3NG0A54kE2FVueuHMkQd8JveYb92eV + dYH4IUrrvJdP5Of9HGi + 5i6GT11nL0dAv / ecyP4sB0jM8rVZzyS8imLarvPUvPuFPvvB8nwYXZ2ZKon4IPjmtC8SPftaw0PSuZKMg735hLCraeAE3lMQbRwiY7yMHKmUHDALG1Ky + HBDiK20vAGEIMwzPwKZmhbBXRGiHzEiXiRk4JgaVyp6N66EALao7VOE7UTzJLs =

我的 php 看起来像这样:

$pagex = $this->page;
$patternx = '/("video_title":")(.*?)(")/i';
if(preg_match($patternx,$pagex,$arx)){  
    $key = $arx[2];
}               


$page = $this->page;
$pattern = '/("video_url":")(.*?)(")/i';
if(preg_match($pattern,$page,$ar)){ 
$link = $ar[2];
}

它不起作用。它什么也没显示。

4

2 回答 2

1
$string = "'disablePauseroll'  : disablePauseroll,
            'video_url'         : encodeURIComponent('WQFuk9Py2VC3jsCrPDJ69xtsj33MiXAElBzQw3TSHqOOyDYL0vRJELrB1hTTW3NG0A54kE2FVueuHMkQd8JveYb92eV+dYH4IUrrvJdP5Of9HGi+5i6GT11nL0dAv/ecyP4sB0jM8rVZzyS8imLarvPUvPuFPvvB8nwYXZ2ZKon4IPjmtC8SPftaw0PSuZKMg735hLCraeAE3lMQbRwiY7yMHKmUHDALG1Ky+HBDiK20vAGEIMwzPwKZmhbBXRGiHzEiXiRk4JgaVyp6N66EALao7VOE7UTzJLs='),
            'encrypted'         : 'true',
            'video_title'       : \"some cool vids title here\",";

preg_match("/encodeURIComponent\('([^']+)/", $string, $match);

echo $match[1]; // URL

preg_match('/video_title[^"]+"([^"]+)/', $string, $match);

echo $match[1]; // Title

这将提取'引号内的文本字符串encodeURIComponent(),第二个将提取引号内的"文本video_title

于 2012-12-25T19:15:20.343 回答
0

对于 video_title(允许"在标题中转义):

'video_title'\s*:\s*"(.*?)*(?<!\\)"

在 PHP 中:

$pattern='\'video_title\'\s*:\s*"(.*?)*(?<!\\)"';

对于网址:

'video_url'\s*:\s*encodeURIComponent\('([^']*)'\)

和:

$pattern='\'video_url\'\s*:\s*encodeURIComponent\(\'([^\']*)\'\)';
于 2012-12-25T19:16:29.277 回答