php preg_替换交换iframe的高度和宽度
我试图在保存到数据库时替换html iframe src上的高度和宽度。我已经看过preg_replace函数和PCRE表达式,但无法计算出来。下面列出的是我的代码和示例输入php preg_替换交换iframe的高度和宽度,php,regex,pcre,Php,Regex,Pcre,我试图在保存到数据库时替换html iframe src上的高度和宽度。我已经看过preg_replace函数和PCRE表达式,但无法计算出来。下面列出的是我的代码和示例输入 $pattern1 = '/width="[0-9]*"/'; $pattern2 = '/height="[0-9]*"/'; $subject = '<iframe src="http://player.vimeo.com/?title=0&byline=0&portrait=0
$pattern1 = '/width="[0-9]*"/';
$pattern2 = '/height="[0-9]*"/';
$subject = '<iframe src="http://player.vimeo.com/?title=0&byline=0&portrait=0" width="400" height="300" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
$returnValue = $preg_replace(array($pattern1, $pattern2), array('width="200"','height="200"'), $subject);
$pattern1='/width=“[0-9]*”/;
$pattern2='/height=“[0-9]*”/;
$subject='';
$returnValue=$preg_replace(数组($pattern1,$pattern2),数组('width=“200”,“height=“200”),$subject);
任何帮助都将不胜感激
干杯,伙计们 因为您要处理HTML,我建议您使用PHP的DOM功能-。使用HTML时,正则表达式很少是答案。您将$放在函数前面
$returnValue = preg_replace(array($pattern1, $pattern2), array('width="200"','height="200"'), $subject);
您的脚本可以通过以下方式简化:
$returnValue = preg_replace('/(width|height)="[0-9]*"/g', '$1="200"', $subject);