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

  • SEARCH
  • Home
  • 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 8215457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:47:33+00:00 2026-06-07T11:47:33+00:00

I am trying to get the source for images on some pages but there

  • 0

I am trying to get the source for images on some pages but there are some differences between the code of the two pages.

Page 1 Code:

<img class="thumb thumb_0" onclick="setImage(0); return false;" src="http://example.com/b1.jpg">

Page 2 Code:

<img style="width: 46px ! important; height: 46px ! important;" class="thumb thumb_0" onclick="setImage(0); return false;" src="http://example.com/image4.jpg">

Notice the difference between the 2 pages… Page 2 has a stupid style at the beginning of the img tag. Also, the “onclick” is located in a different position. The only thing I need to snag is the image location.

Here is the code that I have thus far… which only works for page 1 scenario:

preg_match_all("/<img\s*?class='thumb.*?'.*?src='(.*?)'.*?\/>/is", $hotelPage, $thumbs, PREG_PATTERN_ORDER);

Ideally, I would like to be able to keep it in one php line. How can I do an “or” in preg_replace and how can I get the regex to work for page 2 as well?

Thank you in advance!

UPDATE: The pages have other images, I am only looking for the ones that have a class that contains “thumb”. I apologize for leaving out that heavy detail.

  • 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-06-07T11:47:37+00:00Added an answer on June 7, 2026 at 11:47 am

    This should work as you intended – if your html is in $html, the regular expression should look like the one $reg :

    $html='some html <img class="thumb thumb_0" onclick="setImage(0); return false;"
       src="http://example.com/b1.jpg"> xxx yyy <img class="bummer thumb_0"
       onclick="setImage(0); return false;" src="http://example.com/bummer.jpg">
       <img style="width: 46px ! important; height: 46px ! important;"
       class="thumb thumb_0" onclick="setImage(0); return false;"
       src="http://example.com/image4.jpg"> some html';
    
    $reg = ' <img .+?                # img tag
             class="thumb .+?        # class tag
             src="([^"]+)            # capture src
           ';
    
    preg_match_all("/$reg/xis", $html, $thumbs, PREG_SET_ORDER);
    
    foreach($thumbs as $t) echo $t[1]."\n";
    

    It matches only if the order of attributes is {class, src} and if it found both the img-tag, and the correct class “thumb”. Here we go:

    http://example.com/b1.jpg
    http://example.com/image4.jpg
    

    Only two of three img entries match (I included a third, wrong link in the test set).

    Regards

    rbo

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

Sidebar

Related Questions

I'm trying to get the source attribute of all images withing a specific div
I'm trying to get the source of an internal domain page can have it
I'm trying to get a HTML source of a website through C# code. When
How can I get source code off the internet using SVN? I'm trying to
I am trying to generate some HTML code to list some images for a
I got a package with: $ apt-get source <pkg-name> and now I am trying
I'm trying to get a layout to look like this : (source: yfrog.com )
I'm trying to get zc.buildout to install Gunicorn from source. Using the following configuration:
<trans-unit id=8> <source>Special settings for:</source> <target>Special settings for:</target> </trans-unit> I am trying to get
I am writing java code where i need to get some information from a

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.