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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:07:34+00:00 2026-06-16T01:07:34+00:00

I have an array ($x) containing 748 URL:s. Now, I want to fetch a

  • 0

I have an array ($x) containing 748 URL:s. Now, I want to fetch a specific part from each page and put all those parts into a new array. That is, an array containing 748 pieces of text, each from a different URL defined in array $x.

Here’s the code I’ve got so far:

foreach ($x as $row) {
    $contents = file_get_contents($row);

    $regex = '/delimiter_start(.*?)delimiter_end/s';
    preg_match_all($regex, $contents, $output);
}

If I var_dump $output I get a strange array that endlessly keeps looping content until I press stop in my browser. The array looks like this:

array(2) {
[0]=>
array(1) {
[0]=>
string(4786) "string 1. The one I want from the first page."}

[1]=>
array(1) {
[0]=>
string(4755) "string 1 again"}}

array(2) {
[0]=>
array(1) {
[0]=>
string(8223) "string 2. The one I want from the second page."}

[1]=>
array(1) {
[0]=>
string(8192) "string 2 again"}}

EDIT: I can actually retrieve the results I’m looking for with $output[0]. But how do I create a new array with the same contents as $output[0] that is accessible outside the loop?

  • 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-16T01:07:36+00:00Added an answer on June 16, 2026 at 1:07 am

    The output you are seeing from preg_match_all is standard, this is because you receive the matches and the full matched content in the output array.

    $lines = Array();
    foreach ($x as $row) {
    $contents = file_get_contents($row);
    
    $regex = '/delimiter_start(.*?)delimiter_end/s';
    preg_match_all($regex, $contents, $output);
        if (is_array($output) && isset($output[0]) && !empty($output[0])){
        $lines[] = $output[0];
    }
    }
    var_dump($lines);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array containing specific times and I want when the current time
I have an array of variables all containing text. I want to select only
I have an array containing URL paths, I want to be able to search
I have a 2D array containing all the Piece objects, each an instance of
I have an array containing a list of files. I want to sort it
Ruby 1.8.6 I have an array containing numerical values. I want to reduce it
I have an int array containing gray scale values from 0-254, i also have
I have an array of Objects, each containing a Location and a Links array
I have an array containing the hrefs of colours and I want to go
I have an array containing image URLs, i want to create an image view

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.