用php获取高度和宽度属性?
问题描述:
<img src="......" width="....." height="...."/>
If I have a function generating the above code, how can I get the width and height attributes with php?
&lt; img src =“......”width =“..... “height =”....“/&gt;
code> pre>
如果我有一个函数生成上面的代码,我如何用php获取width和height属性 ? p>
div>
答
Do you mean something like this ?
So you would need to use
preg_match_all('/(alt|title|src)=("[^"]*")/i',$img_tag, $img[$img_tag]);
And then foreach them to array.
答
You can use getimagesize()
<?php
list($width, $height, $type, $attr) = getimagesize("http://example.com/image.gif");
?>
<img src="..." width="<?= $width ?> height="<?= $height ?>" />