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

Link to comment
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??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.