c_pattle Posted January 26, 2013 Share Posted January 26, 2013 I have a .sql file that has the following in it DROP TABLE IF EXISTS `flights`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `flights` ( `flight_id` int(11) NOT NULL AUTO_INCREMENT, `flight_icon` int(11) NOT NULL, `flight_path` int(11) NOT NULL, `flight_from` int(11) NOT NULL, `flight_to` int(11) NOT NULL, PRIMARY KEY (`flight_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; I have read the contents of the file using file_get_contents. I was wondering what is the best way to strip out everything before "CREATE TABLE" and everything after "CHARSET=latin1"? Does anyone have any suggestions on the best way to do it? Thanks Quote Link to comment Share on other sites More sharing options...
bspace Posted January 27, 2013 Share Posted January 27, 2013 sure you want to remove the drop table? to remove the comments /* remove comments */ $string = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $string); Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 27, 2013 Share Posted January 27, 2013 Why don't you just edit the SQL file? Quote Link to comment Share on other sites More sharing options...
lbh2011 Posted January 27, 2013 Share Posted January 27, 2013 DROP TABLE IF EXISTS `flights`; CREATE TABLE `flights` ( `flight_id` int(11) NOT NULL AUTO_INCREMENT, `flight_icon` int(11) NOT NULL, `flight_path` int(11) NOT NULL, `flight_from` int(11) NOT NULL, `flight_to` int(11) NOT NULL, PRIMARY KEY (`flight_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.