我有这个代码:
<object height="510" width="650">height="510"width="650">
或此代码:
<objectheight="345"width="123'> height='456'width=789>
值周围的引号可以是double、single或none。单词可以放在一起,也可以有一个或多个空格。重要的是数字作为值可以是任何东西
所以,我需要用我自己的 variable替换height="510
" (or height='123'
or ) 中的整数值。height=456
$height_val
到目前为止我的代码:
$height_val = "640";
$pattern = ??? // this regex I need to find out
$replacement = $height_val;
$string = '<objectheight="345"width="123\'> height=\'456\'width=789>'
$result = preg_replace($pattern, $replacement, $string);
最后的结果应该是<objectheight="640"width="123\'> height=\'640\'width=789>