Home > Backend Development > PHP Tutorial > 这个正则怎么写

这个正则怎么写

WBOY
Release: 2016-06-23 13:48:20
Original
950 people have browsed it

 我要取出表名。


回复讨论(解决方案)

这个数组里些是创建表的sql语句,然后我想要获取到表名,帮写个正则 - -

<?php$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]);    }}?>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template