I am trying to create a php function that will parse a html, and alter or <img> tags to add the alt and title attributes that will match the src filename.
If you do not know html this is what I am trying to do.
Code: Select all
<img src="http://www.someserver.com/.../ferrari.jpg">Code: Select all
<img src="http://www.someserver.com/.../ferrari.jpg" alt="ferrari" title="ferrari" >So function should work like this
1. Accept a string containing html with zero or more <img> tags
2. Extract the name of the image from the src attribute. src can be found in several forms:
src="http:/.../image.ext"
src = "http:/.../image.ext"
src ='http:/.../image.ext'
src=http:/.../image.ext
3. Add alt="image" and title="image" (without extension) to the <img> tag
4. Repeat for all images
5. Return altered html (yikes!)
Any gurus out there?