我正在尝试替换[picasa和],但以下代码段无效。
$vars = '[picasa flashvars="host=picasaweb.google.com&hl=en_US&feat=flashalbum&RGB=0x000000&feed=https%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F100016363917755589270%2Falbumid%2F5578059546640576577%3Falt%3Drss%26kind%3Dphoto%26hl%3Den_US" width="288" height="192"]';
$patterns[0] = "/\[picasa\] /";
$patterns[1] = "/\]/";
$replacements[0] = "<embed type='application/x-shockwave-flash' src='https://picasaweb.google.com/s/c/bin/slideshow.swf'";
$replacements[1] = " pluginspage='http://www.macromedia.com/go/getflashplayer'>";
$match = preg_replace($patterns,$replacements,$vars);
echo $match;
我知道我可以使用str_replace,但我想改用preg_replace。
我在这里做错了吗?
答案 0 :(得分:2)
$patterns[0]
匹配[picasa]
$vars
应该是:
preg_replace('/\[picasa\s*([^\]]+)\]/',$replacements[0].'$1'.$replacements[1],$vars);