开发者

PHP - Why isn't preg_replace working?

I am trying to replace [picasa and ], but the following code snippet is not working.

$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] = 开发者_Python百科"<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;

I know that I can use str_replace, but I would like to use preg_replace instead.

Am I doing some wrong here?


$patterns[0] matches [picasa] which isn't in $vars

It should be:

preg_replace('/\[picasa\s*([^\]]+)\]/',$replacements[0].'$1'.$replacements[1],$vars);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜