Created
February 5, 2021 11:04
-
-
Save dgwyer/4241721bbcd05469e8b9abe035dd96e9 to your computer and use it in GitHub Desktop.
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 | |
$source_file = 'readme.txt'; | |
$target_file_pro = 'tmp/changelog-pro.md'; | |
$target_file_free = 'tmp/changelog-free.md'; | |
$handle = fopen($source_file, 'r'); | |
$changelog_pro = []; | |
$changelog_free = []; | |
if ($handle) { | |
$write_mode = null; | |
while (($line = fgets($handle)) !== false) { | |
if (strpos($line, 'Changelog') == true) { | |
array_push($changelog_pro, $line); | |
array_push($changelog_free, $line); | |
continue; | |
} | |
// set up write mode | |
if (strpos($line, 'fs_premium_only_begin')) { | |
$write_mode = 'pro'; | |
continue; | |
} else if(strpos($line, 'fs_free_only_begin')) { | |
$write_mode = 'free'; | |
continue; | |
} | |
// never write if we're on an end directive | |
if (strpos($line, 'fs_premium_only_end') || strpos($line, 'fs_free_only_end')) { | |
continue; | |
} | |
if(!empty($write_mode) && $write_mode === 'pro') { | |
array_push($changelog_pro, $line); | |
} else if(!empty($write_mode) && $write_mode === 'free') { | |
array_push($changelog_free, $line); | |
} | |
} | |
fclose($handle); | |
} else { | |
echo('error opening the file'); | |
} | |
file_put_contents($target_file_pro, $changelog_pro); | |
file_put_contents($target_file_free, $changelog_free); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment