Preg Replace 视频对象代码 - 仅适用于第一个实例
任何人都可以帮助我解释为什么以下代码仅适用于目标代码中宽度/高度的第一个实例。我需要替换使用“height: xxx ; width : xxx”的样式,然后替换实际嵌入的高度=“xxx”和宽度=“xxx”
这是预替换:
$vid_object = preg_replace('~((width)\s?[=:]\s?[\'"]?)[0-9]+~i','${1}600',$vid_object);
$vid_object = preg_replace('~((height)\s?[=:]\s?[\'"]?)[0-9]+~i','${1}364',$vid_object);
这是视频输出:
<object style="height: 364px; width: 600px"><param name="movie" value="http://www.youtube.com/v/UF06-2Q0-G0?version=3"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/UF06-2Q0-G0?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object>
我认为它有与代码“${1}600”的替换部分有关,或者结果仅限于第一个实例。
非常感谢任何帮助。当正则表达式不是我的专长时,浪费了太多时间。 谢谢 尼古拉斯
Can anyone help me decipher why the following code only works on the first instance of width / height in an object code. I need to replace both the style which use "height: xxx ; width : xxx" and then also replace the actual embed's height = "xxx" and width = "xxx"
here's the preg replace:
$vid_object = preg_replace('~((width)\s?[=:]\s?[\'"]?)[0-9]+~i','${1}600',$vid_object);
$vid_object = preg_replace('~((height)\s?[=:]\s?[\'"]?)[0-9]+~i','${1}364',$vid_object);
here's the video output:
<object style="height: 364px; width: 600px"><param name="movie" value="http://www.youtube.com/v/UF06-2Q0-G0?version=3"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/UF06-2Q0-G0?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object>
I think it has something to do with the replacement part of the code '${1}600' or that the results are limited to first instance.
Any help is greatly appreciated. Wasted too much time hunting when regex isn't my specialty.
Thanks
nicholas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下
范围更广一些。
当我在你提供的代码上运行它时,我得到了
try
It's a little broader.
When I run that on the code you provided I get
正如沙德所说,这确实是魔法引号的问题。我刚刚在 $_POST 数据上使用了 stripslahes。
Just as Shad suggested this was indeed a problem with the magic quotes being on. I just used the stripslahes on the $_POST data.