Php 按新行拆分MySQL转储

Php 按新行拆分MySQL转储,php,regex,preg-split,array-filter,Php,Regex,Preg Split,Array Filter,我有一个字符串(来自mysql转储): 我想获取和数组以执行: Array( [0]=>CREATE TABLE IF NOT EXISTS `categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `parent` int(11) DEFAULT NULL, `description` text NOT NULL,

我有一个字符串(来自mysql转储):

我想获取和数组以执行:

Array(
   [0]=>CREATE TABLE IF NOT EXISTS `categories` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `name` varchar(255) NOT NULL,
      `parent` int(11) DEFAULT NULL,
      `description` text NOT NULL,
      `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
      `ordering` int(11) NOT NULL DEFAULT '1000',
      `published` tinyint(1) NOT NULL,
      `image` varchar(255) NOT NULL,
      `banner_id` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`),
      KEY `parent` (`parent`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ;
   [1]=> INSERT INTO `categories` (`id`, `name`, `parent`, `description`, `created`, `ordering`, `published`, `image`, `banner_id`) VALUES
    (1, 'Anniversary', 0, 'Lorem Ipsum; is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry''s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.', '2015-07-13 00:00:00', 0, 1, 'images/flowers/1.jpg', 2),
    (5, 'Get Well', 0, 'Lorem Ipsum; is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry''s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.', '2015-07-13 00:00:00', 5, 1, 'images/flowers/6.jpg', 0);
)
我尝试使用:

$sql_array = array_filter(explode(';', trim(preg_replace('/\s\s+/', ' ', $extension->sql))));
但我错了,因为我不能被-;
谢谢

我用分号和换行符分开

$sql\u array=preg\u split(“/;\n/”,$extension->sql)

或者可能是
”/\r\n/“
根据行的结尾,我想您可以这样做:
$sql\u array=array\u filter(explode(;\n“,$extension->sql))
$sql_array = array_filter(explode(';', trim(preg_replace('/\s\s+/', ' ', $extension->sql))));