Created
October 13, 2023 03:48
-
-
Save cagrimmett/5260af01f5f9642ff7677d52e88fdff4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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