Skip to content

Instantly share code, notes, and snippets.

@cagrimmett
Created October 13, 2023 03:48
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 cagrimmett/5260af01f5f9642ff7677d52e88fdff4 to your computer and use it in GitHub Desktop.
Save cagrimmett/5260af01f5f9642ff7677d52e88fdff4 to your computer and use it in GitHub Desktop.
<?php
if ($argc !== 2) {
echo "Usage: php csv-to-opml.php <csvFilePath>\n";
exit(1);
}
$csvFilePath = $argv[1];
// Define the output OPML file path
$opmlFilePath = 'output.opml'; // You can customize the output file name here
// Read CSV and generate OPML
$csvFile = fopen($csvFilePath, 'r');
if ($csvFile !== false) {
$opml = '<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<head>
<title>Generated OPML</title>
</head>
<body>
';
while (($data = fgetcsv($csvFile)) !== false) {
// $title = isset($data[0]) ? trim($data[0]) : '';
$url = isset($data[0]) ? trim($data[0]) : '';
if (!empty($url)) {
// Append "/feed" to the end of the URL
$url .= '/feed';
$opml .= ' <outline category="peekskill" type="rss" xmlUrl="' . htmlspecialchars($url) . '" />' . PHP_EOL;
}
}
$opml .= ' </body>
</opml>';
fclose($csvFile);
// Write OPML to the output file
file_put_contents($opmlFilePath, $opml);
echo 'OPML file generated successfully!';
} else {
echo 'Error opening CSV file.';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment