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 Link to comment https://forums.phpfreaks.com/topic/273677-stripping-out-block-of-text-in-file/ 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); Link to comment https://forums.phpfreaks.com/topic/273677-stripping-out-block-of-text-in-file/#findComment-1408455 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? Link to comment https://forums.phpfreaks.com/topic/273677-stripping-out-block-of-text-in-file/#findComment-1408456 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; Link to comment https://forums.phpfreaks.com/topic/273677-stripping-out-block-of-text-in-file/#findComment-1408467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.