1
<img src="......" width="....." height="...."/>

If I have a function generating the above code, how can I get the width and height attributes with php?

2
  • 1
    Ca you please elaborate question with suitable example? Commented Oct 1, 2011 at 5:23
  • Why is this tagged wordpress, is it a wordpress function generating the above code? Commented Oct 1, 2011 at 12:09

2 Answers 2

1

You can use getimagesize()

<?php    
     list($width, $height, $type, $attr) = getimagesize("http://example.com/image.gif");
?>
<img src="..." width="<?= $width ?> height="<?= $height ?>" />
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.