·

photo credit: DSCN2817.JPG via photopin (license)

Programatically prefix the img src attribute with a domain name

Tags: ,

I just wanted to share this with you guys, because otherwise I might forget it: This is a simple method to prefix the src -attribute of an img -tag with a specific domain name. This method takes HTML like:

And prefixes it like this:

This is ideal for when you got HTML from WYSIWYG-editors for example that don’t always prefix the image tag, or other sources that don’t add a domain name to the image tag. So here’s the method:

 

Visitors give this article an average rating of 3.7 out of 5.

How would you rate this article?

Leave a Reply