hi!
I need to add alt, width and height attributes to img tags scattered throughout a textfile. I can get the width and height with getimagesize(), but I havn't figured out how to find the img tags and add the attributes. Any help is most welcome.

    you could use str_replace perhaps... you'd have to assign all of your content to a variable, then run it through the function and echo out what's left.

    $code = str_replace("<img", "<img width='xxx' height='xxx' alt='xxx'", $code);
    

    If you search for <img only, it'll simply insert the width/height/alt before the src (which I'm assuming is already present in the tag).

    Hope that helps...

      That might be a good start...

      The problem is that I don't know the heights or the widths of the images, but if I can get the path to the image, I can find the right values with getimagesize(). My problem is that I don't know how to add these to the img tag.

        Write a Reply...