【发布时间】:2010-08-17 05:54:50
【问题描述】:
我编写了一个正则表达式,用于提取用户输入的值并替换一些高度和宽度值并保留 URL。这样可以安全地将其添加到数据库中。
这是我目前所拥有的(只是试图让 preg_match 返回一个 TRUE 值)
$test ='<object height="81" width="100%"> <param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Ftheshiverman%2Fsummer-beats-july-2010&secret_url=false"></param> <param name="allowscriptaccess" value="always"></param> <embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fsoundcloud.com%2Ftheshiverman%2Fsummer-beats-july-2010&secret_url=false" type="application/x-shockwave-flash" width="100%"></embed> </object>';
if (preg_match('/<object height=\"[0-9]*\" width=\"[0-9]*\"><param name=\"movie\" value=\"(.*)\"><\/param><param name=\"allowscriptaccess\" value=\"always\"><\/param><embed allowscriptaccess=\"always\" height=\"[0-9]*\" src=\".*\" type=\"application\/x-shockwave-flash\" width=\"100%\"><\/embed><\/object>/', $test)) {
$embed = $test;
} else {
$embed = 'FALSE';
}
我似乎在验证中做错了什么,因为它总是返回 false。
【问题讨论】:
-
用正则表达式解析 (X)HTML 是 dangerous business.
标签: php regex preg-match embedded-video