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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:30:03+00:00 2026-05-27T10:30:03+00:00

I am working on a Webinterface that provides the same function like poEdit. I

  • 0

I am working on a Webinterface that provides the same function like poEdit.

I want to walk trough all .php files in a specified folder and search every line for a translation. For this I would like to use regular expression searching the actual line in the php file and return the translation-text-parameter and the domain-parameter.

My function looks like this:

__('This is my translation', 'domain');

But because for the domain-parameter I defined a default, the function __() can also be called like this:

__('this is my translation');

Now in PHP i tried to use the Function preg_match_all() but i can’t gent my regex together.

Here is an example of a possible line in the script and the output array I would like to receive with the preg_match_all() function:

echo __('Hello World'); echo __('Some domain specific translation', 'mydomain');

Array output:

Array
(
    [0] => Array
        (
            [0] => Hello World
        )

    [1] => Array
        (
            [0] => Some domain specific translation.
            [1] => mydomain
        )
)

Can anyone help me out with the Regex and the preg_math_all() flags?

Thank you guys.

  • 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-27T10:30:04+00:00Added an answer on May 27, 2026 at 10:30 am

    Something like this should work. Array shift needed, because zero element will always contain full match, there is no flag to exclude it AFAIK.

    if(preg_match_all('/__\(\s*\'((?:[^\']|(?<=\\\)\')+)\'(?:\s*,\s*\'((?:[^\']|(?<=\\\)\')+)\')?\s*\)/us', $data, $result)) {
      foreach ($result as &$item) {
        array_shift($item);
      }
      unset($item);
      var_dump($result);
    }
    

    It finds correctly calls like these __(‘lorem \’ ipsum’, ‘my\’domain’). It would fail on __(‘lorem \\’) though.

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

Sidebar

Related Questions

I'm working on a PHP web interface that will receive huge traffic. Some insert/update
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project that parses a log of events, and then updates a
Working with TCL and I'd like to implement something like the Strategy Pattern .
I find myself working in an environment where all I have access to is
I'm working with a closed community site (PHP-based) of about 100 users, and one
My Zend application is going to get an command line php script that should
Working with stl:list and stl::vector types under interrupt handlers I want to avoid malloc()
I'm finally getting my team to embrace source code management now that we're working
The HR department at the company that I am currently working for has requested

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.