Skip to content

Instantly share code, notes, and snippets.

@Arty2
Created September 10, 2017 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arty2/2213cd541ce389cf76961ff91362c16e to your computer and use it in GitHub Desktop.
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.
<?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