Page 1 of 1

Mutli-mode mode

Posted: Fri May 26, 2006 5:55 pm
by LiveFree
Well I thought I had it fixed..... :lol:

Now I have this block of SQL and I need to match the very top line and the very last character on the last line

So I know I need to use the 'm' modifier after the pattern delimiter to put it into multi-line mode, but what I dont know is the operator or character that signals the end and beinning of the block ($ ^ only work for the lines, not blocks now in multiline mode).

Ex. preg_match("/[CHARACTER FOR BEGINNING OF BLOCK HERE]CREATE TABLE[[:space:]]$table [CHARACTER FOR END OF BLOCK HERE];/im")

And the SQL is like this...

CREATE TABLE `nuke_topics` (
`topicid` int(3) NOT NULL auto_increment,
`topicname` varchar(20) default NULL,
`topicimage` varchar(100) default NULL,
`topictext` varchar(40) default NULL,
`counter` int(11) NOT NULL default '0',
PRIMARY KEY (`topicid`),
KEY `topicid` (`topicid`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

Except there are 30 other commands like it, but Im trying to find the one that has the table name in the first line

Thanks a bunch :)

Posted: Fri May 26, 2006 6:11 pm
by feyd
why not just a regex for the first line then a substr for the last character?

Posted: Fri May 26, 2006 6:32 pm
by LiveFree
Hey Feyd,

Thanks for that, I would have never though to do that D'oh!

But when I have this...

Code: Select all

CREATE TABLE `nuke_users` (
  `user_id` int(11) NOT NULL auto_increment,
  `name` varchar(60) NOT NULL default '',
  `username` varchar(25) NOT NULL default '',
  `user_email` varchar(255) NOT NULL default '',
  `femail` varchar(255) NOT NULL default '',
  `user_website` varchar(255) NOT NULL default '',
  `user_avatar` varchar(255) NOT NULL default '',
  `user_regdate` varchar(20) NOT NULL default '',
  `user_icq` varchar(15) default NULL,
  `user_occ` varchar(100) default NULL,
  `user_from` varchar(100) default NULL,
  `user_interests` varchar(150) NOT NULL default '',
  `user_sig` text,
  `user_viewemail` tinyint(2) default NULL,
  `user_theme` int(3) default NULL,
  `user_aim` varchar(255) default NULL,
  `user_yim` varchar(255) default NULL,
  `user_msnm` varchar(255) default NULL,
  `user_password` varchar(40) NOT NULL default '',
  `storynum` tinyint(4) NOT NULL default '10',
  `umode` varchar(10) NOT NULL default '',
  `uorder` tinyint(1) NOT NULL default '0',
  `thold` tinyint(1) NOT NULL default '0',
  `noscore` tinyint(1) NOT NULL default '0',
  `bio` tinytext NOT NULL,
  `ublockon` tinyint(1) NOT NULL default '0',
  `ublock` tinytext NOT NULL,
  `theme` varchar(255) NOT NULL default '',
  `commentmax` int(11) NOT NULL default '4096',
  `counter` int(11) NOT NULL default '0',
  `newsletter` int(1) NOT NULL default '0',
  `user_posts` int(10) NOT NULL default '0',
  `user_attachsig` int(2) NOT NULL default '1',
  `user_rank` int(10) NOT NULL default '0',
  `user_level` int(10) NOT NULL default '1',
  `broadcast` tinyint(1) NOT NULL default '1',
  `popmeson` tinyint(1) NOT NULL default '0',
  `user_active` tinyint(1) default '1',
  `user_session_time` int(11) NOT NULL default '0',
  `user_session_page` smallint(5) NOT NULL default '0',
  `user_lastvisit` int(11) NOT NULL default '0',
  `user_timezone` decimal(5,2) NOT NULL default '0.00',
  `user_style` tinyint(4) default NULL,
  `user_lang` varchar(255) NOT NULL default 'english',
  `user_dateformat` varchar(14) NOT NULL default 'D M d, Y g:i a',
  `user_new_privmsg` smallint(5) unsigned NOT NULL default '0',
  `user_unread_privmsg` smallint(5) unsigned NOT NULL default '0',
  `user_last_privmsg` int(11) NOT NULL default '0',
  `user_emailtime` int(11) default NULL,
  `user_allowhtml` tinyint(1) default '1',
  `user_allowbbcode` tinyint(1) default '1',
  `user_allowsmile` tinyint(1) default '1',
  `user_allowavatar` tinyint(1) NOT NULL default '1',
  `user_allow_pm` tinyint(1) NOT NULL default '1',
  `user_allow_mass_pm` tinyint(1) default '4',
  `user_allow_viewonline` tinyint(1) NOT NULL default '1',
  `user_notify` tinyint(1) NOT NULL default '0',
  `user_notify_pm` tinyint(1) NOT NULL default '1',
  `user_popup_pm` tinyint(1) NOT NULL default '1',
  `user_avatar_type` tinyint(4) NOT NULL default '3',
  `user_sig_bbcode_uid` varchar(10) default NULL,
  `user_actkey` varchar(32) default NULL,
  `user_newpasswd` varchar(32) default NULL,
  `points` int(10) default '0',
  `last_ip` varchar(15) NOT NULL default '0',
  `user_wordwrap` smallint(3) NOT NULL default '70',
  `agreedtos` tinyint(1) NOT NULL default '0',
  `user_allowsignature` tinyint(4) NOT NULL default '1',
  `user_report_optout` tinyint(1) DEFAULT '0' NOT NULL,
  `user_show_quickreply` tinyint(1) NOT NULL default '1',
  `user_quickreply_mode` tinyint(1) NOT NULL default '1',
  `user_color_gc` varchar(6) default '',
  `user_color_gi` text,
  `user_showavatars` tinyint(1) default '1',
  `user_showsignatures` tinyint(1) default '1',
  `user_time_mode` tinyint(4) NOT NULL default '6',
  `user_dst_time_lag` tinyint(4) NOT NULL default '60',
  `user_pc_timeOffsets` varchar(11) NOT NULL default '0',
  `user_view_log` tinyint(4) NOT NULL default '0',
  `user_glance_show` varchar(255) NOT NULL default '1',
  `user_hide_images` tinyint(2) NOT NULL default '0',
  `user_open_quickreply` TINYINT(1) DEFAULT '1' NOT NULL,
  PRIMARY KEY  (`user_id`),
  KEY `uid` (`user_id`),
  KEY `uname` (`username`),
  KEY `user_session_time` (`user_session_time`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

--
-- Dumping data for table `nuke_users`
--
And I use the following code to get the ';' after the AUTO_INCREMENT:

Code: Select all

preg_match("/CREATE[[]]TABLE[[]]$table/i", $install, $block);
			  $block = substr($block[0], -1, 1);
I get the ending ` of the 'Dumping data for table `nuke_users` string, which shouldn't happen :S

Any help is appriciated!