0

Firstly - some background. We have a config.php file which lists several variables and settings in this format:

$MY_EMAIL_ADDRESS    = '[email protected]';
$MY_WEBSITE          = 'www.test.com';
$SOMETHING_ELSE      = 'foobar';

I would like to replace them with more sensible (and secure) names as part of an array, throughout the entire PHP project. Mostly so we can do this more securely: Get PHP variable value via Ajax with variable name as parameter

We have also forgotten some of these variables names, so that they are used throughout the project, but possibly not documented - hence doing a search one-by-one will prove difficult.

Is there a way I can search the php files for any values that start with a dollar sign ($) and then are made up of only upper case letters and possibly underscores?

$MY_SETTING_NAME

We could then either build a list and update manually, or build some kind of script to replace things with a more sensible way of working:

$CONFIG['MY_SETTING_NAME']

Thank you!

1
  • You can do a regex text search on your php scripts in your IDE or code editor. /\$([A-Z0-9_]+)\s?=)/ should work. Commented Apr 28, 2012 at 17:41

1 Answer 1

1

You can use get_defined_vars function which will return all variables as array.

Please look at php.net website for example

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for answering, but this will need to be done on a non-running application (ie. in the source code). I think the Regex answer above should do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.