start by splitting into lines:
PHP Code:
$data = "
abase v. To lower in position, estimation..
....
";
$lines = explode("\r\n", $data);
then go through each line and try to make sense of it using regular expressions:
PHP Code:
foreach($lines as $line) {
if(preg_match("^([a-z-]+) (v|n)\. (.*)$", $line, $matches)) {
/*the regex says "some letters or hyphens, a space, then a v or an n then a dot, then anything" if there are other types other than v or n then just add them separated by a vertical pipe */
$word = $matches[1];
$type = $matches[2];
$definition = $matches[3];
/* now you've got your data you can do what you like with it, probably best to echo it out first couple of times to make sure that the pattern is matching it correctly, then put a mysql statement here */
mysql_query("INSERT INTO words (word, type, definition) VALUES ('".addslashes($word)."', '".addslashes($type)."', '".addslashes($definition)."')");
} else {
//line didn't match pattern- maybe echo for manual investigation
}
}
Bookmarks