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 8235259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:44:45+00:00 2026-06-07T18:44:45+00:00

I have an blog entry which has multiple images in it (sometimes one, sometimes

  • 0

I have an blog entry which has multiple images in it (sometimes one, sometimes two, sometimes three) and looks a bit like this:

<a href="http://xxx/" rel="attachment w133>
  <img class="yyy" title="title1" src="http://xxx/title1.jpg" alt="" width="650" height="487" />
</a>
<a href="http://xxx/" rel="attachment w134">
  <img class="yyy" title="title2" src="http://xxx/title2.jpg" alt="" width="650" height="487" />
</a>
<a href="http://xxx/" rel="attachment w135">
  <img class="yyy" title="title3" src="http://xxx/title3.jpg" alt="" width="650" height="487" />
</a>

with some text following this.

Now, I wonder how I can use preg_match_all to extract that first part. I now somewhat about PHP programming, but never used preg_match_all.

This code here does extract the last image only, which is not enough:

$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post_content, $matches);

It would be great if someone could give me a hint how to achieve that, if it’s possible at all. Thanks so much!

  • 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-07T18:44:47+00:00Added an answer on June 7, 2026 at 6:44 pm
    $post_content='<a href="http://xxx/" rel="attachment w133>
      <img class="yyy" title="title1" src="http://xxx/title1.jpg" alt="" width="650" height="487" />
    </a>
    <a href="http://xxx/" rel="attachment w134">
      <img class="yyy" title="title2" src="http://xxx/title2.jpg" alt="" width="650" height="487" />
    </a>
    <a href="http://xxx/" rel="attachment w135">
      <img class="yyy" title="title3" src="http://xxx/title3.jpg" alt="" width="650" height="487" />
    </a>
    ';
    
    preg_match_all('/<a\s[^>]*href=([\"\']??)([^\" >]*?)\\1[^>]*>(.*)<\/a>/siU', $post_content, $matches);
    //print_r ($matches);//$matches - array which contains all your images
    print $matches[0][0]; //first link with image
    print $matches[0][1]; //second link with image
    print $matches[0][2]; //third link with image
    

    Output:

    <a href="http://xxx/" rel="attachment w133&gt;
      &lt;img class=" yyy"="" title="title1" src="http://xxx/title1.jpg" alt="" width="650" height="487">
    </a>
    <a href="http://xxx/" rel="attachment w134">
      <img class="yyy" title="title2" src="http://xxx/title2.jpg" alt="" width="650" height="487">
    </a>
    <a href="http://xxx/" rel="attachment w135">
      <img class="yyy" title="title3" src="http://xxx/title3.jpg" alt="" width="650" height="487">
    </a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a blog app which its model has an author field like
I found a blog entry which suggests that sometimes c# compiler may decide to
I was a bit inspired by this blog entry http://blogs.technet.com/dmelanchthon/archive/2009/07/23/windows-7-rtm.aspx (German) The current notion
I'm constructing a [CalendarDay] which looks like this newtype CalendarDay = MKCal (Either AvailableDay
I have read this excellent blog entry on the woes of strong naming and
I have two tables. Posts and Replies. Think of posts as a blog entry
I have a sidebar navigation that lists blog entry titles down the side of
I have a blog (designed with blogger) and there's one problem. If I access
I have a blog that has a redirect loop, and I can't understand htaccess
I have a blog installed in www.foo.com/wp/ and would like all requests that go

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.