Matching through define() blocks
Posted: Tue Nov 27, 2007 7:09 am
EDIT: for some reason its doubling the spaces on the first block of code i have here. Ignore the double spaced stuff.
I have php files that hold my translations and I am working on a script that while viewing a page, it gives me a link that says "translate this page" and then it lets you translate it. Fun, cool, awesome, I know!
The problem I am having is I can't get this regex down to help me extract the phrases and their keys. An example file that I am having problem with looks exactally like this:
and what I am doing is this:
but if I print_r($matches) it only gives me these ones:
So obviously the regex I am using is not good but I don't see the problem. Can someone shed some light on this one?
I have php files that hold my translations and I am working on a script that while viewing a page, it gives me a link that says "translate this page" and then it lets you translate it. Fun, cool, awesome, I know!
The problem I am having is I can't get this regex down to help me extract the phrases and their keys. An example file that I am having problem with looks exactally like this:
Code: Select all
<?php
define('USERS_RAKEBACK_CALCULATOR_TITLE', 'Poker Rakeback Calculator - Use rakeback calculator to estimate your rake and rakeback');
define('USERS_RAKEBACK_CALCULATOR_NAV_CALCULATE_RAKEBACK', 'Calculate Rakeback');
define('USERS_RAKEBACK_CALCULATOR_POKER_RAKEBACK_CALCULATOR', 'Poker Rakeback Calculator');
define('USERS_RAKEBACK_CALCULATOR_BLURB_PARAGRAPH_1', 'To get an estimate of how much rake you are paying and your expected rakeback, enter your game type and time played per week in the rakeback calculator.');
define('USERS_RAKEBACK_CALCULATOR_GAME_TYPE', 'Game Type:');
define('USERS_RAKEBACK_CALCULATOR_TABLES_SIMULTANEOUSLY', 'Tables simultaneously:');
define('USERS_RAKEBACK_CALCULATOR_1_TABLE', '1 table');
define('USERS_RAKEBACK_CALCULATOR_2_TABLES', '2 tables');
define('USERS_RAKEBACK_CALCULATOR_3_TABLES', '3 tables');
define('USERS_RAKEBACK_CALCULATOR_4_TABLES', '4 tables');
define('USERS_RAKEBACK_CALCULATOR_5_TABLES', '5 tables');
define('USERS_RAKEBACK_CALCULATOR_6_TABLES', '6 tables');
define('USERS_RAKEBACK_CALCULATOR_TIME_PLAYED_PER_WEEK', 'Time played per week:');
define('USERS_RAKEBACK_CALCULATOR_4_HOURS_CASUAL', '4hrs - Casual');
define('USERS_RAKEBACK_CALCULATOR_8_HOURS_WEEKENDER', '8hrs - Weekender');
define('USERS_RAKEBACK_CALCULATOR_12_HOURS_HOBBYIST', '12hrs - Hobbyist');
define('USERS_RAKEBACK_CALCULATOR_20_HOURS_AMATEUR', '20hrs - Amateur');
define('USERS_RAKEBACK_CALCULATOR_30_HOURS_SEMI_PRO', '30hrs - Semi Pro');
define('USERS_RAKEBACK_CALCULATOR_40_HOURS_PROFESSIONAL', '40hrs - Professional');
define('USERS_RAKEBACK_CALCULATOR_60_HOURS_POKER_FREAK', '60hrs - Poker Freak');
define('USERS_RAKEBACK_CALCULATOR_RAKEBACK', 'Rakeback:');
define('USERS_RAKEBACK_CALCULATOR_DAILY_RAKE_AND_RAKEBACK', 'Daily rake $%1$s and rakeback <b>$%2$s</b>');
define('USERS_RAKEBACK_CALCULATOR_WEEKLY_RAKE_AND_RAKEBACK', 'Weekly rake $%1$s and rakeback <b>$%2$s</b>');
define('USERS_RAKEBACK_CALCULATOR_MONTHLY_RAKE_AND_RAKEBACK', 'Monthly rake $%1$s and rakeback <b>$%2$s</b>');
?>
Code: Select all
$contents = file_get_contents($file_path);
preg_match_all("#define\(\'([A-Z_]+)\', \'(.*)\'\);#", $contents, $matches);
Code: Select all
Array
(
[0] => Array
(
[0] => define('USERS_RAKEBACK_CALCULATOR_TITLE', 'Poker Rakeback Calculator - Use rakeback calculator to estimate your rake and rakeback');
[1] => define('USERS_RAKEBACK_CALCULATOR_NAV_CALCULATE_RAKEBACK', 'Calculate Rakeback');
[2] => define('USERS_RAKEBACK_CALCULATOR_POKER_RAKEBACK_CALCULATOR', 'Poker Rakeback Calculator');
[3] => define('USERS_RAKEBACK_CALCULATOR_MONTHLY_RAKE_AND_RAKEBACK', 'Monthly rake $%1$s and rakeback $%2$s');
)
[1] => Array
(
[0] => USERS_RAKEBACK_CALCULATOR_TITLE
[1] => USERS_RAKEBACK_CALCULATOR_NAV_CALCULATE_RAKEBACK
[2] => USERS_RAKEBACK_CALCULATOR_POKER_RAKEBACK_CALCULATOR
[3] => USERS_RAKEBACK_CALCULATOR_MONTHLY_RAKE_AND_RAKEBACK
)
[2] => Array
(
[0] => Poker Rakeback Calculator - Use rakeback calculator to estimate your rake and rakeback
[1] => Calculate Rakeback
[2] => Poker Rakeback Calculator
[3] => Monthly rake $%1$s and rakeback $%2$s
)
)