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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:37:01+00:00 2026-06-16T04:37:01+00:00

Function in my php code: private function get_first_images($html){ preg_match_all(‘/<img.+src=[\’]([^\’]+)[\’].*>/i’, $html, $matches); if(isset($matches[1]) && isset($matches[1][0])

  • 0

Function in my php code:

private function get_first_images($html){
    preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $html, $matches);
    if(isset($matches[1]) && isset($matches[1][0]) && !empty($matches[1][0])){
        return $matches[1][0];
    }else{
        return false;
    }
}

is pulling the second image instead of the first. Here is an example of the xml it is looking at:

<![CDATA[
<a href="http://mls-photos.diversesolutions.com/355/1246202/0-full.jpg?15054836" target="_blank"><img src="http://mls-photos.diversesolutions.com/355/1246202/0-medium.jpg?15054836" alt="Property Photo" /></a><br /><br /><img src="http://cdn1.diverse-cdn.com/idx-v2/mls-icons/rein.png" alt="Mls Icon" /><br /><br /><b>3 beds, 2 full, 1 part baths</b><br />Home size: 1,700 sq ft<br />Lot Size: 0 sq ft<br />Property Type: Residential, Residential / Detached<br />MLS Number: 1246202<br />Community: North Norfolk<br />Tract: East Beach<br /><br /><br />Beautiful New Home With Wrap Around Porch, 10 Ft. Ceilings On First Floor, Hardwood Floors, Custom Cabinets, Granite, One Block To The Beach. Real Cedar Shake Exterior. Corner Lot. Carriage House Unfinished. <br /><br />Listed with Keller Williams Realty<br /><hr noshade="noshade" /><br /><b>Brought to you by Virginia Beach Real Estate Team, Keller Williams Realty. Call me today at 757-215-4246, or visit my website at <a href="http://www.vbret.com" target="_blank">www.vbret.com</a>!</b><br /><br /><p>Users of this Site are granted a limited, nonexclusive license to use the Site and its listing content for personal and noncommercial use only.
 </p>
 <p>
 Real Estate Information Network, Inc. (REIN) updates its listings on a daily basis. Data last updated: 12/21/12 7:55 AM PST. Some properties which appear for sale on this website may have subsequently sold or may no longer be available.
 </p>
 <p>
 All Information Deemed Reliable But Not Guaranteed.
 </p>
 <p>
 REIN's listings are based upon data submitted by its Broker Members, and REIN therefore makes no representation or warranty regarding the accuracy of the data. All users of REIN's listings database should confirm the accuracy of the listing information directly with the listing agent. This data and information is protected under Federal Copyright laws. Federal law prohibits, among other acts, the unauthorized copying or alteration of, or preparation of derivative works from, all or any part of copyrighted materials, including certain compilations of data and information. COPYRIGHT VIOLATORS MAYBE SUBJECT TO SEVERE FINES AND PENALTIES UNDER FEDERAL LAW.
 </p><hr noshade="noshade" />
]]>

How do I fix it so that it pulls the first image and not the second?

  • 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-16T04:37:03+00:00Added an answer on June 16, 2026 at 4:37 am

    You need to make the + ungreedy :

    private function get_first_images($html){
        preg_match_all('/<img.+?src=[\'"]([^\'"]+)[\'"].*>/i', $html, $matches);
        if(isset($matches[1]) && isset($matches[1][0]) && !empty($matches[1][0])){
            return $matches[1][0];
        }else{
            return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inherited some C# code where a PHP page containing the function &decrypt
Here is my code of SessionManager.php : private function generateAuthToken($user) { $bits = '';
Having php code: function getChildren($parent_id = 0) { .... return $SomeChildrenArray; } And Smarty
this is function.php of a wordpress theme that NOD32 says this code have a
Can anyone explain the following PHP Code ? function get_param($param_name, $param_type = 0) {
This is the PHP code I have. function decrypt($s_input, $s_key, $s_iv) { $s_decrypted =
This is the php code for date format on my web page function starkers_posted_on()
Can anyone explain what the following PHP Code does function query($query_string) { if ($query_string
What is the c#.net equivalent for php's preg_replace function? php code is like this:
I have a function that finds a regex thingy, then replaces with php code.

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.