Created
September 10, 2017 00:51
-
-
Save Arty2/2213cd541ce389cf76961ff91362c16e to your computer and use it in GitHub Desktop.
A tool to convert AJ-Fork (Cutenews) data into a well-formated CSV for import into WordPress or other.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
2017-09-10 | |
A tool to convert AJ-Fork (Cutenews) data into a well-formated CSV for import into WordPress or other. | |
*/ | |
$input = file('data.txt'); | |
$output = fopen('data.csv','w+'); | |
$entries = 0; | |
function aj_prepareTitle($title) { | |
$title = strtolower($title); | |
$title = str_replace("å", "aa", $title); | |
$title = str_replace("ø", "o", $title); | |
$title = str_replace("æ", "ae", $title); | |
$title = preg_replace('/&.+?;/', '', $title); // kill entities | |
$title = preg_replace('/[^a-z0-9 _-]/', '', $title); | |
$title = preg_replace('/\s+/', ' ', $title); | |
$title = str_replace(' ', '-', $title); | |
$title = preg_replace('|-+|', '-', $title); | |
$title = trim($title, '-'); | |
return $title; | |
} | |
foreach ($input as $null => $line) { | |
@list($date, $user, $title,$short,$unused1,$unknown1, $cat, $unknown3) = explode('|',trim($line)); | |
$news = array( | |
"id" => $date, | |
"date" => date("Y-m-d\TH:i:s",$date), | |
"author" => $user, | |
"title" => str_replace ('"', '“', $title); | |
"slug" => aj_prepareTitle($title), | |
"short" => str_replace('{nl}',"\n",$short), | |
"category" => $cat, | |
); | |
fputcsv($output, $news); | |
$entries++; | |
} | |
echo 'entries parsed: ' . $entries; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment