Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php preg_替换交换iframe的高度和宽度_Php_Regex_Pcre - Fatal编程技术网

php preg_替换交换iframe的高度和宽度

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&amp;byline=0&amp;portrait=0

我试图在保存到数据库时替换html iframe src上的高度和宽度。我已经看过preg_replace函数和PCRE表达式,但无法计算出来。下面列出的是我的代码和示例输入

$pattern1 = '/width="[0-9]*"/';
$pattern2 = '/height="[0-9]*"/';
$subject  = '<iframe src="http://player.vimeo.com/?title=0&amp;byline=0&amp;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);