preg_match_all problem

I have a php file with lines like

define(‘BUTTON_IMAGE_ADD_TO_CART’, ‘button_add_to_cart.gif’);

and

define(‘BUTTON_CREATE_ACCOUNT_ALT’, ‘Sign Up’);

I want to get all of the first type of line and return it as

BUTTON_IMAGE_ADD_TO_CART button_add_to_cart.gif <br />

I’m pretty sure preg_match_all is the way to do it but I’m a newbie when it comes to this kind of thing.

I can load the file using file_get_contents() but all my matching efforts seem to fail

All help appreciated.

Welcome to SitePoint!

Not ideal, but off the top of my head…


<?php
function get_script_constants($script){
  $pre = get_defined_constants();
  include $script;
  return array_diff(
    get_defined_constants(),
    $pre
  );
}

print_r(
  get_script_constants('local/path/to/script.php')
);

/*
  Array
  (
      [BUTTON_GIF] => button.gif
  )
*/

Just the job.

Thank you