如何匹配可能具有动态属性文本的方括号标签?
我正在尝试替换 [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 代替。
我在这里做错了什么吗?
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] = "<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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$patterns[0]
匹配[picasa]
,但它不在$vars
中,它应该是:
$patterns[0]
matches[picasa]
which isn't in$vars
It should be: