Jump to content

convert string to mysql insert


samoht

Recommended Posts

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 <[email protected]><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??

Link to comment
https://forums.phpfreaks.com/topic/128587-convert-string-to-mysql-insert/
Share on other sites

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??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.