How to write this regular expression ?? & Nbsp; name of the table to be retrieved. ------ Solution ---------------------- & lt ;? Php $ array & nbsp; array (CREATE & nbsp; TABLE & nbsp; 'Order _ log_1 '& nbsp; (' _ id' & nbsp; int (11) & nbsp; NOT & nbsp; NULL & nbsp; how to write this regular expression of AUTO ??
I want to retrieve the table name.
------ Solution ----------------------
$array = array("CREATE TABLE `order_log_1` (`_id` int(11) NOT NULL AUTO_INCREMENT,,`order_info` text,`insert_time` int(11) DEFAULT NULL,PRIMARY KEY (`_id`))",
"CREATE TABLE `order_log_2` (`_id` int(11) NOT NULL AUTO_INCREMENT,,`order_info` text,`insert_time` int(11) DEFAULT NULL,PRIMARY KEY (`_id`))",
"CREATE TABLE `order_log_3` (`_id` int(11) NOT NULL AUTO_INCREMENT,,`order_info` text,`insert_time` int(11) DEFAULT NULL,PRIMARY KEY (`_id`))",
);
$pattern = '/CREATE TABLE `(\w+)`/i';
foreach ($array as $item) {
if (preg_match($pattern, $item, $match)) {
var_dump($match[1]);
}
}
?>