Unable to make regexp work...
Posted: Wed Nov 05, 2008 9:26 am
Can't seem to make this work, what did i do wrong?
EDIT: The statement is not valid, some information has been changed from the original statement to produce effects to test other regexp, please don't discuss the format of the CREATE STATEMENT as it is effectively not valid in certain points but it should not affect the result of the regexp.
Outputs:
Expect:
Code: Select all
$createstatement = 'CREATE TABLE `amsp_communiques` ( `id` int(10,3) unsigned NOT NULL auto_increment, `sys_validate` datetime NOT NULL default \'0000-00-00 00:00:00\', `body` text collate utf8_unicode_ci NOT NULL, `resume` varchar(250) collate utf8_unicode_ci NOT NULL default \'\', `title` varchar(150) collate utf8_unicode_ci NOT NULL default \'\', `sys_status` tinyint(3) unsigned NOT NULL default \'0\', PRIMARY KEY (`id`, `added`)) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
preg_match_all('#primary\s*key\s*\(\s*(`([\w]+[\w\d]*)`[\s,]*)*\)#i', $createstatement, $primarykeydefinition);
print_r($primarykeydefinition);
Outputs:
Code: Select all
Array
(
[0] => Array
(
[0] => PRIMARY KEY (`id`, `added`)
)
[1] => Array
(
[0] => `added`
)
[2] => Array
(
[0] => added
)
)
Code: Select all
Array
(
[0] => Array
(
[0] => PRIMARY KEY (`id`, `added`)
)
[1] => Array
(
[0] => `id`
[1] => `added`
)
[2] => Array
(
[0] => id
[1] => added
)
)