我有我已经写,以便提取一个用户输入的值和替换一些高度和宽度值和保持URL的正则表达式。这是因为它可以安全地添加到数据库中。嵌入代码的正则表达式将不起作用
这是我迄今为止(只是想获得的preg_match返回真值)
$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用正则表达式是[危险的事情。(http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-自包含的标签/ 1732454#1732454) – NullUserException 2010-08-17 06:07:58