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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:00:53+00:00 2026-06-06T15:00:53+00:00

I have files with texts an constants. How can I get constant name and

  • 0

I have files with texts an constants. How can I get constant name and constant value. Problem is that constant value has sometime spaces. I read files with file() and then with foreach…

Example:

define('LNG_UTF-8',         'Universal Alphabet (UTF-8)');
define('LNG_ISO-8859-1',   'Western Alphabet (ISO-8859-1)');
define('LNG_CustomFieldsName', 'Custom Field');
define('LNG_CustomFieldsType', 'Type');

I already tried:

to get constant name:

$getConstant1 = strpos($mainFileArray[$i], '(\'');
$getConstant2 = strpos($mainFileArray[$i], '\',');              
$const = substr($mainFileArray[$i], $getConstant1 + 2, $getConstant2 - $getConstant1 - 2);

to get constant value

$position1 = strpos($file[$i], '\',');
$position2 = strpos($file[$i], '\');');

$rest = substr($file[$i], $position1 + 3, $position2 - $position1 - 2);

but not working when is space or ‘,’…

How can i make this always working??

  • 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-06T15:00:55+00:00Added an answer on June 6, 2026 at 3:00 pm

    A regular expression matching this would be this:

    preg_match("/define\(\s*'([^']*)'\s*,\s*'([^']*)'\s*\)/i", $line, $match);
    echo $match[1], $match[2];
    

    See http://rubular.com/r/m9plE2qQeT.

    However, that only works if the strings are single quoted ', don’t contain escaped quotes, the strings are not concatenated etc. For example, this would break:

    define('LNG_UTF-8', "Universal Alphabet (UTF-8)");
    define('LNG_UTF-8', 'Universal \'Alphabet\' (UTF-8)');
    define('LNG_UTF-8', 'Universal Alphabet ' . '(UTF-8)');
    // and many similar
    

    To make at least the first two work, you should use token_get_all to parse the PHP file according to PHP parsing rules, then go through the resulting tokens and extract the values you need.
    To make all cases work, you need to actually evaluate the PHP code, i.e. include the file and then simply access the constants as constants in PHP.

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

Sidebar

Related Questions

I have two text files that contain columnar data of the variety position -
I have seen config files(yes, text files) for various console applications that look like
Can anybody help with a valid regex ? I have a files containing functions
I have a set of XML files that I am processing with an XSL
I have web.rb file that works fine. I wanted to move all require files
Possible Duplicate: Avoiding repeated constants in CSS I have a javascript file that I
I have a code base that can be customized for different customers. This is
I have a text file that lists the name of a track then after
I have an app that allows users to save and open text files. Saving
I have text files containing structured data (it is a proprietary format and not

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.