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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:12:28+00:00 2026-05-17T06:12:28+00:00

Had to deploy some PHP code onto a shared server with only PHP5.2.8. All

  • 0

Had to deploy some PHP code onto a shared server with only PHP5.2.8. All code works EXCEPT for the preg_filter() call which was added in 5.3+ (and against which the code was written).

Can anyone recommend an easy substitute for preg_filter() in PHP5.2?

  • 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-17T06:12:29+00:00Added an answer on May 17, 2026 at 6:12 am

    PHP manual says that preg_filter() is identical to preg_replace() except it only returns the matches.

    So, you can use a combination of preg_replace and array_diff to get results like preg_filter in PHP 5.2.x. Do it like this:

    <?php
    $subject = array('1', 'a', '2', 'b', '3', 'A', 'B', '4'); 
    $pattern = array('/\d/', '/[a-z]/', '/[1a]/'); 
    $replace = array('A:$0', 'B:$0', 'C:$0'); 
    
    $result = preg_replace($pattern, $replace, $subject);
    var_dump($result);
    
    //take difference of preg_replace result and subject
    $preg_filter_similar = array_diff($result, $subject);
    
    var_dump($preg_filter_similar);
    ?>
    

    This gives the output (with xDebug installed):

    array
      0 => string 'A:C:1' (length=5)
      1 => string 'B:C:a' (length=5)
      2 => string 'A:2' (length=3)
      3 => string 'B:b' (length=3)
      4 => string 'A:3' (length=3)
      5 => string 'A' (length=1)
      6 => string 'B' (length=1)
      7 => string 'A:4' (length=3)
    array
      0 => string 'A:C:1' (length=5)
      1 => string 'B:C:a' (length=5)
      2 => string 'A:2' (length=3)
      3 => string 'B:b' (length=3)
      4 => string 'A:3' (length=3)
      7 => string 'A:4' (length=3)
    

    Which is same as preg_filter() output:

    Array
    (
        [0] => A:C:1
        [1] => B:C:a
        [2] => A:2
        [3] => B:b
        [4] => A:3
        [7] => A:4
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a look at http://sharepoint.microsoft.com/blogs/GetThePoint/Lists/Posts/Post.aspx?ID=154 and I wonder if the running commentary on
I've been trying to deploy my ASP.NET MVC 3 Beta Application to my hosting.
The last time I deployed on a device was last week. Since that time,
So I created an app (with lots of help from SO and my friends).
Why does git log --decorate not display more than one tag per commit? EDIT
I'm using the Rails gem SimpleForm, but I think my question may be applicable
I have a problem regarding to the software deployment. We're using JBoss 4.2.3. Please
I've searching for this for a while now online (Google, and StackOverflow), but haven't
We've got an application using spring for making calls to DB2 stored procedures. The
Traditionally I have always written my sql scripts by hand so they are nice

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.