regex image tag
Posted: Mon Sep 26, 2005 12:25 am
I want to post images on my blog but don not want to break the table. I need a code that searches through my string to find image tags, then finds the size of that image. Then it checks if the image is too big and resize it down. I don't need the image to be physically resized but instead just have the html width and height declare it.
Can someone pleaes help. I can do the size conversion to keep the image proportional. i just need the regex that searches for image tags and replace it.
basically, i want to convert:
<img src="http://www.myimage.jpg">
to something like:
<img src-"ttp://www.myimage.jpg" width="500" height="400">
Would it be something like this?
$anchor = preg_replace('/\<img src="([^\]]+)\]([^\[]+)\[\/">\]/i', "<img src=\"$1\">$2 height=\"$h\" width=\"$w\"\">", $string);
Can someone pleaes help. I can do the size conversion to keep the image proportional. i just need the regex that searches for image tags and replace it.
basically, i want to convert:
<img src="http://www.myimage.jpg">
to something like:
<img src-"ttp://www.myimage.jpg" width="500" height="400">
Would it be something like this?
$anchor = preg_replace('/\<img src="([^\]]+)\]([^\[]+)\[\/">\]/i', "<img src=\"$1\">$2 height=\"$h\" width=\"$w\"\">", $string);