Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1808080
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:13:00+00:00 2026-05-17T06:13:00+00:00

I have some HTML and want to replace the src attributes of all the

  • 0

I have some HTML and want to replace the “src” attributes of all the img tags so that they point to copies of the identical images (although with different file names) on another host.

So for instance, given these three tags

<IMG SRC="../graphics/pumpkin.gif" ALT="pumpkin">
<IMG BORDER="5" SRC="redball.gif" ALT="*"> 
<img alt="cool image" src="http://www.crunch.com/pic.jpg"/>

I would like them replaced with

<IMG SRC="http://myhost.com/cache/img001.gif" ALT="pumpkin">
<IMG BORDER="5" SRC="http://myhost.com/cache/img002.gif" ALT="*"> 
<img alt="cool image" src="http://myhost.com/cache/img003.jpg"/>

I know there is some regexp magic to this, just not sure what it should look like (or if this is in fact the best way).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:13:01+00:00Added an answer on May 17, 2026 at 6:13 am

    I tried doing this with SimpleHTMLDOM, and it seems to work:

    $html = str_get_html( ... ); // what you have done
    
    $map = array(
      "../graphics/pumpkin.gif"       => "http://myhost.com/cache/img001.gif",
      "redball.gif"                   => "http://myhost.com/cache/img002.gif",
      "http://www.crunch.com/pic.jpg" => "http://myhost.com/cache/img003.gif",
    );
    
    foreach ($html->find("img") as $element) {
      if (isset($map[$element->src])) {
        $element->src = $map[$element->src];
      }
    }
    
    echo $html;
    

    PS: If you need to clarify your question, you should edit your original question instead of opening a new, identical question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to replace some HTML tags that I have in a CDATA element,
I have some text contain html tags, I would like to replace all links
I have some html files that I want to convert to text. I have
I have some text that has HTML hyper-links in it. I want to remove
I have some data enclosed in HTML tags. I want to insert this data
I want to locate all image tags in my html with src not containing
I want to find all HTML tags from the input strings and removed/replace with
I have string that contains html . The html has several img tags in
I have some text that I want to match and replace in C# The
I have some html files with their own css. I want to use them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.