1
wtravel
String to Arrays to MySQL table

Maybe someone can help me out with this. I have a string:

#li##a href=http://test.foo.com#Test site#/a# - Overview ...#li##a href=http://shop.bar.com#Shopping site#/a# - Shopping site ...

----------
I would like the data in this string stored in a MySQL table, like this:

id url name description
-------------------------------------------------
1 test.foo.com Test site Overview ...
2 shop.bar.com Shopping site Shopping ...

How can I achieve this? I was thinking about making an array with an array for each record and then with a function write it to MySQL table. But from theory to practice I got stuck actually.

Kind regards,

Martijn


2
fatman
Re: String to Arrays to MySQL table
  • 2004/3/4 15:13

  • fatman

  • Friend of XOOPS

  • Posts: 176

  • Since: 2003/12/13


do you have any way to change the seperators in your string? If i'm reading it right your sting is built like this.

# name ## url # description

if you use the explode function in php

$myarray explode('#'$string );


You should get an array with each element as an item, and a blank item between 'name' and 'url'.

You could then loop through this array to build your sql making sure to skip the blank value. My looping isn't the greatest other wise I would attempt an example.

Ideally if you can define the seperators in your string, use a different seperator between each 'row' and another one between each field. Then you could do.

// assuming each row was seperated by #
$myarray explode('#'$string );

// assuming each field was seperated by ;
foreach ( $myarray as $k=>$row )
{
  
$myarray[$k] => explode(';'$row);
}

that would give you the array with an array for each record.




Login

Who's Online

818 user(s) are online (310 user(s) are browsing Support Forums)


Members: 0


Guests: 818


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits