我有一个像这样的html(它的flash for flash player):
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的值,使其成为:
echo $ 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];
}
它不起作用。它没有显示任何内容。
答案 0 :(得分: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
引号中提取文本
答案 1 :(得分:0)
对于video_title(允许标题中的转义"
):
'video_title'\s*:\s*"(.*?)*(?<!\\)"
在PHP中:
$pattern='\'video_title\'\s*:\s*"(.*?)*(?<!\\)"';
对于网址:
'video_url'\s*:\s*encodeURIComponent\('([^']*)'\)
和
$pattern='\'video_url\'\s*:\s*encodeURIComponent\(\'([^\']*)\'\)';