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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:05:24+00:00 2026-05-27T03:05:24+00:00

I am doing some data munging on documents which may (or may not –

  • 0

I am doing some data munging on documents which may (or may not – as the case may be) have ocurrence(s) of a regular expression pattern in their content.

I would like to write a PHP function to use to process the documents – the job of the function is to return an array of all matching patterns sound in the document (if they exist), or to return an empty array if no matches were found.

I am sure that this involves using the PHP function preg_match_all, however, I do not understand the format of the array returned by preg_match_all. I simply want to return a 1 dimensional (i.e. non-nested array) of the strings that match as follows:

<?php 

   $pattern = "^[h].[a-z]{3,4}";
   $doc = file_get_contents('some_pathname');

   function get_matching_patterns($pattern, $doc){
     $out = array();

     if (strlen($doc) && strlen($pattern)){
        // not sure about this - I don't like the complicated nested array returned
        // by preg_match-all
        preg_match_all($pattern, $doc, $out); 
     }

     return out;
   }
?>
  • 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-05-27T03:05:24+00:00Added an answer on May 27, 2026 at 3:05 am
    • You’re missing a $
    • In your case you can simply return $out[0]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have lots of code which is doing some data processing (in C# to
I've been doing some Web-Projects lately that rely on heavy Data-Binding and have been
I am currently doing some research which involves analyzing data coming from different sensors.
Im doing some data cleansing on some messy data which is being imported into
So I am doing some data analysis in which I am required to extract
I'm doing some test data loading with SSIS into our data warehouse and have
I'm doing some data analysis in Matlab, and anytime I call the hold function
I am doing some research about how to access data in a UniData database
I'm doing some archiving to a property list and when I unarchive my data
One thing I've started doing more often recently is retrieving some data at the

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.