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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:28:41+00:00 2026-06-09T04:28:41+00:00

I create an array of image URLs: $matches = array(); preg_match_all(‘#(http://[^\s]*?\.jpg)#i’,$html, $matches); $matches2 =

  • 0

I create an array of image URLs:

$matches = array();

preg_match_all('#(http://[^\s]*?\.jpg)#i',$html, $matches);

$matches2 = array_unique($matches); // get unique

echo "there are ".count($matches2)." items!";

print_r($matches);

The count shows me I have one result, but, the result is something like as follows:

there are 1 items!

Array ( [0] => 

Array ( 
[0] => http://testmenow.com/248472104410838590_J3o6Jq50_b.jpg 
[1] => http://testmenow.com/cirrow_1338328950.jpg 
[2] => http://testmenow.com/madi0601-87.jpg 
[3] => http://testmenow.com/swaggirll-4.jpg 
[4] => http://testmenow.com/erythie-35.jpg ))

Subsequently, when I try to print out each image from the URL I only get the first one in the array when using this:

foreach ($matches2 as $image) {

echo '<img src='.$image[0].' width=200 height=200>';

}

I need to be able to print each array item separately – I think i’m confusing something somewhere but two hours later…still at same place

  • 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-09T04:28:43+00:00Added an answer on June 9, 2026 at 4:28 am

    preg_match_all returns an array for each submatch. That means that $matches[0] ist the array that contains your expected result.
    Your code should look like this:

    preg_match_all('#http://[^\s]*?\.jpg#i',$html, $matches);
    $matches2 = array_unique($matches[0]); // get unique
    echo "there are ".count($matches2)." items!";
    
    foreach ($matches2 as $image) {
        echo '<img src='.$image.' width=200 height=200>';
    }
    

    You can omit the brackets in your regex since this is already matched.

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

Sidebar

Related Questions

Admin: Please create image urls as images I'm trying to achieve the following output:
I need to create an array of images in which, every time I tap,
I create array: TextBox[] textarray = new TextBox[100]; Then in cycle set this params,
How to create array of generic type? How does generic Arrays.copyOf() method work? It
Can c++ create array of pointers to different classes dynamically loaded from dll? ps.without
All, I have the following code: $context = stream_context_create(array( 'http' => array( 'timeout' =>
I create an array that then prints in sets of five. I want to
I need to create an array for time that I will use in a
I need to create an array of label and text boxes dynamically. I have
I want to create an array of arrays in PowerShell. $x = @( @(1,2,3),

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.