I need a way to convert several hundred htm files into the mambo / joomla CMS. There is a script here: http://forum.joomla.org/index.php/topic,982.html That is supposed to do this, but I can't get it to work. I need this to work, or I need a way to get it to work. I NEED a way to parse htm code in files, and convert it into a sql entry that will place that code into the mambo / joomla database the same way the CMS would, only I don’t have to do all 2,000 of them via copy and paste. As you can see in the forum, it was a generic script that I guess HAS worked for some, but just not me. I don't think it's an mambo specific thing, I actually think it's a php issue. I don't think it's scripted correctly. Or perhaps I haven't modified it correctly. I even installed apache, and PHP on my home machine JUST to run the script. Same thing. It doesn't strip anything out of it, yet it does seem to see all the files. I've played around with the tags that script is supposed to deal with, but I don't know php well enough to do so. As far as the script. The script is supposed to look at files in a certain directory. Parse ALL of them, look at only the tags posted in the code, and post a sql entry that will pop all that information into a database so that mambo would see it. Pretty much replicating what mambo does when it posts information to the database, but instead of MANUALLY doing all 2k of them, I want it somewhat automated Thanks for the help, Grinch
I'd also like to add that I'll pay $25 bucks for anyone that can get this working for me. Thanks I'll send via paypal.
$lines = file('somehtml.html'); foreach($lines as $line) { if(!preg_match('/<body>/',$line)) { $outfile[] = $line; } } // the array $outfile will contain the lines of the file with the exception of the <body> tag PHP:
Thanks you for your help, but I'm afraid I have no clue on how to impliment that. I'm not a php programmer. My offer still stands for the 25 dollars if you can get the following script to work. I imagine it wouldn't take much to pop that code you posted somewhere in this script, but not only do I need the THIS script to work becuase it converts the infomation in the files into a sql entry that I can then send to a sql file, and run it from phpadmin. If you want to rewrite this code, so be it, but I need the code to have the following. 1. I need to specify the catagory ID, and section ID seperatly. 2. Needs to generate the sql code for every file in the directory (into multiple sql entries) I think that should do it. <?php /** * Textonly convert to mambo * @author Adam van Dongen **/ $dir = "D:/Mijn_documenten/TIM/mambo/free/article_import/articles"; //directory that contains the files $title_start = '<h3 class="post-title">'; $title_end = '</h3>'; $content_start = '<div class="post-body">'; $content_end = '<!-- Begin \#comments -->'; $date_start = '<h2 class="date-header">'; $date_end = '<!-- Begin .post -->'; $cat_id = 1; //categories in which all these articles will be inserted $sectionid = 1; //section in which this categorie is. $prefix = "mos_"; $files = readFilesFromDir($dir); for($i=0,$n=count($files);$i<$n;$i++){ //echo '-----------------------------------------------------------------<br /><br />'; $file = file_get_contents($dir . "/" . $files[$i]); $title = preg_match('#' . $title_start . '(.*)' . $title_end . '#is', $file, $matches); $titel = strip_tags($matches[1]); //echo $titel . '<br />'; $matches = null; $content = preg_match('#' . $content_start . '(.*)' . $content_end . '#is', $file, $matches); $content = addslashes(strip_tags($matches[1], '<b><br><br /><strong><em><table><td><tr><img>')); //echo $content . '<br />'; $matches = null; $date = preg_match('#' . $date_start . '(.*)' . $date_end . '#is', $file, $matches); $date = strip_tags($matches[1]); //echo $date . '<br />'; $date = explode(', ', $date); //print_r($date); $month = explode(" ", $date[1]); $day = $month[1]; $month = convertToMonth($month[0]); $year = trim($date[2]); $date = $year . "-" . $month . "-" . $day; //echo $date . '<br />'; //continue; $query = "INSERT INTO " . $prefix . "content (title, introtext, state, sectionid, catid, created) VALUES ('$titel', '$content', 1, $sectionid, $cat_id, '$date');\n"; echo htmlentities($query, ENT_COMPAT, 'UTF-8') . '<br />'; } function readFilesFromDir($dir){ $array = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $array[] = $file; } } closedir($handle); } return $array; } function convertToMonth($m){ switch($m){ case 'January': return "01"; break; case 'February': return "02"; break; case 'March': return "03"; break; case 'April': return "04"; break; case 'May': return "05"; break; case 'June': return "06"; break; case 'July': return "07"; break; case 'August': return "08"; break; case 'September': return "09"; break; case 'October': return "10"; break; case 'November': return "11"; break; case 'December': return "12"; break; } } ?>
You can't upload articles, but you can import them using phpadmin, which allows you to pop the sql entries right into the database. Same way the program does through the CMS.