我需要在输出中替换所有图像中的样式参数 例如
struct objects objs[objectcount];
我需要
$output = '<p><img src="" style="float: left; width: 600px; height: 400px">
some text <img src="" style="float: right; width: 600px; height: 300px">';
请帮助
答案 0 :(得分:1)
解决
$output = preg_replace_callback('#<img (.+) style="(.+)" />#isU',
function($matches) {
$styles = explode('; ', $matches[2]);
foreach ($styles as $i) {
if (strstr($i, 'width')) $styles['w'] = $i;
if (strstr($i, 'height')) $styles['h'] = $i;
}
$width = $styles['w'];
$width = str_replace('width:', '', $width);
$width = str_replace('px', '', $width);
$height = $styles['h'];
$height = str_replace('height:', '', $height);
$height = str_replace('px', '', $height);
return '<img ' . $matches[1] . ' width="' . $width . '" height="' . $height . '">';
}
, $output);