Hi, just use 2 "preg_match_all" function calls and a bit of php inbetween them to build up an array of optiongroups / options:
PHP Code:
<?php
$data = join("", file("http://www.yaproom.com/interests.txt"));
$optgroups = array();
if( preg_match_all('/<optgroup label="(.*?)">(.*?)<\/optgroup>/is', $data, $matches ) ){
$cnt = count($matches[1]);
for( $i = 0; $i < $cnt; $i++){
$optgroups[$matches[1][$i]] = array();
if( preg_match_all("/<option value='[0-9]*'>(.*?)<\/option>/is", $matches[2][$i], $options) ){
$cnt2 = count($options[1]);
for( $j = 0; $j < $cnt2; $j++){
$option = $options[1][$j];
$optgroups[$matches[1][$i]][] = $option;
}
}
}
}
foreach( $optgroups as $n=>$options ){
echo '"'.$n.'"';
echo "\n";
echo join("\n", $options)."\n";
}
?>
That will print out a text list in the format you listed in your post (optgroup name in "" followed by a list of option names, etc)
$optgroups will be an array like this:
array (
"Option Group 1" => array("Option 1", "Option2", etc),
"Option Group 2" => array("Option 1", "Option2", etc),
etc, etc
So you can just step through the array and insert data into mysql with mysql_query()s...
hope that helps,
Sam