Разделить дамп MySQL новой строкой

У меня есть строка (из дампа mysql):

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 ;

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);

И я хотел бы получить и массив для выполнения:

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))));

Но я не прав, так как не могу разделить на -;
Спасибо!

0

Решение

Я разделил бы точку с запятой с последующим переводом строки.

$sql_array = preg_split('/;\n/', $extension->sql);

Или возможно '/;\r\n/' в зависимости от концов строки

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector