需要有关 php 中简单的 preg_match/preg_replace 正则表达式的帮助
我正在尝试执行一项简单的任务,即使用共同的宽度/高度更改数千个音乐视频嵌入代码。
例如,我有以下代码:
<object width="480px" height="407px" >
<param name="allowFullScreen" value="true"/>
<param name="wmode" value="transparent"/>
<param name="movie" value="http://mediaservices.myspace.com/services/media/embed.aspx/m=1311720,t=1,mt=video"/>
<embed src="http://mediaservices.myspace.com/services/media/embed.aspx/m=1311720,t=1,mt=video"
width="480" height="407" allowFullScreen="true"
type="application/x-shockwave-flash"
wmode="transparent">
</embed>
</object>
仅为了易读性而添加换行符
我需要编辑
首先,我试图找出现有视频的宽度/高度...找到宽高比...然后用新值替换现有值(宽度=“640”和高度=“xxx”这是基于视频的宽高比)。
I'm trying to do a simple task of altering thousands of music video embed codes with a common with/height.
For example, I have the following code:
<object width="480px" height="407px" >
<param name="allowFullScreen" value="true"/>
<param name="wmode" value="transparent"/>
<param name="movie" value="http://mediaservices.myspace.com/services/media/embed.aspx/m=1311720,t=1,mt=video"/>
<embed src="http://mediaservices.myspace.com/services/media/embed.aspx/m=1311720,t=1,mt=video"
width="480" height="407" allowFullScreen="true"
type="application/x-shockwave-flash"
wmode="transparent">
</embed>
</object>
Line breaks added only for legibility
I need to edit the width/height parameters in both the <object>
and <embed>
tags, one having a 'px' suffix, and the other not having one at all (which is totally random, some codes have it in all cases, others do not).
Firstly, I'm trying to find out the width/height of the existing video.... finding the aspect ratio... and then replacing the existing values with the new values (width = "640" and height="xxx" which is based on the aspect ratio of the video).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是获取宽度和高度的方法
计算新的高度,如下所示:
并像这样替换:
Here's how to get the width and height
Calculate the new height like this:
And replace like so:
使用 SimpleHTMLDOM:
Using SimpleHTMLDOM: