samoht Posted October 15, 2008 Share Posted October 15, 2008 hello, I have a old guestbook that was using a cgi script to dump user input into a html file with out put that looks like: <b>Bet you make beautiful babies.</b><br> Tamara Becks <tbecki@aol.com><br> Franklin, TN USA - Friday, August 01, 2008 at 08:08:06 (EDT)<hr> I need to go through this file and convert all these entries to mysql inserts so they can be kept safe in a db I have a nice php based guestbook now and everything is working fine - I just need to get all the old entries into the db so they can be accessed by the new guestbook mysql insert looks like: INSERT INTO `jos_phocaguestbook_items` (`id`, `catid`, `sid`, `username`, `userid`, `email`, `homesite`, `ip`, `title`, `content`, `date`, `published`, `checked_out`, `checked_out_time`, `ordering`, `params`) VALUES (101, 1, 0, 'Alex Fregal',0,'','','','Tuscon, AZ USA', 'Saw you in Tuscon in 2005.', '2008-09-26 11:41:53', 1, 0, '0000-00-00 00:00:00', 1, ''), So you can see that the date being reformatted is one of the tricky issues and the order of the text make simple find and replace not easy. Any Ideas?? Quote Link to comment Share on other sites More sharing options...
prexep Posted October 15, 2008 Share Posted October 15, 2008 Preg_Match_all the file take each part you want into a array and foreach it into the query. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 15, 2008 Share Posted October 15, 2008 Except for the "at" the date is easy to handle $d = 'Friday, August 01, 2008 08:08:06 (EDT)' ; echo date ('Y-m-d H:i:s', strtotime($d)); --> 2008-08-01 13:08:06 Quote Link to comment Share on other sites More sharing options...
samoht Posted October 16, 2008 Author Share Posted October 16, 2008 how would I preg match the file? I did set the whole file into a variable string - is that a good way to get control over it? Quote Link to comment Share on other sites More sharing options...
samoht Posted October 16, 2008 Author Share Posted October 16, 2008 I have something like this: preg_match_all("|<[^>]+>(.*)</[^>]+>|U",$oldStuff,$out,PREG_PATTERN_ORDER); where $oldStuff is the string variable. Now my string is has these tags: <b></b><br><br><hr> for each entry the message would be between the <b></b> The name would be between the first<br> and the second<br> the location between the second<br> and a - the date and time between the - and the <hr> how do I set up the first argument in preg_match_all to account for this?? 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.