eric2453 Posted April 2, 2008 Share Posted April 2, 2008 I have a mailing list archived in a bunch of files. Each file is in the following format: [some HTML at beginning] ----------------------- [first message] ----------------------- [second message] ... ----------------------- [last message] ----------------------- [some HTML at end] I want to take all these files and import each message (=the text between "--------"'s) into a MySql entry. Can anyone give me hints as to do this? Should I use PHP or Perl or something else? I am a total beginner with these languages. Anyone just want to write the script for me? It doesn't look hard :-) Thanks! Link to comment https://forums.phpfreaks.com/topic/99169-phpmysql-question/ Share on other sites More sharing options...
Catfish Posted April 2, 2008 Share Posted April 2, 2008 You need to find a pattern in the files to work with. If you literally have "-----------" between each message you can use that as a delimiter between each message in the file. You might want to read up on regular expressions as you can use the preg functions in PHP to search, match, replace text using regular expressions. Check the PHP manual under Function Reference for this. (Note: I have made reference to preg which is the Perl regular expression functions. I think there are more REGEXP function in PHP, I just use the Perl compatible ones because that's where I first learnt REGEXP.) If you can work out how to use regular expression functions then doing what you asked will become a piece of pie and you might find regular expressions rather addictive Link to comment https://forums.phpfreaks.com/topic/99169-phpmysql-question/#findComment-507344 Share on other sites More sharing options...
r-it Posted April 2, 2008 Share Posted April 2, 2008 firstly i suggest you use str_replace the many ----- with a character like "^" and then you use the strtok function to break them apart and maybe store in an array or something, then insert into database Link to comment https://forums.phpfreaks.com/topic/99169-phpmysql-question/#findComment-507345 Share on other sites More sharing options...
lordfrikk Posted April 2, 2008 Share Posted April 2, 2008 If you have the same amount of "-" between each message, you can simply use this: <?php $file = "test.txt" $messages = explode("-----------------------", file_get_contents($file)); ?> Link to comment https://forums.phpfreaks.com/topic/99169-phpmysql-question/#findComment-507351 Share on other sites More sharing options...
eric2453 Posted April 3, 2008 Author Share Posted April 3, 2008 Thanks! Looks like I'll start with "explode", and if the ----- turn out not to all have the same length, I'll have to get my hands dirty with regular expressions. And great icon "r-it", I rubbed that about three times before figuring out what it was Link to comment https://forums.phpfreaks.com/topic/99169-phpmysql-question/#findComment-508310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.