Skip to content

Instantly share code, notes, and snippets.

Created September 22, 2016 21:59
Show Gist options
  • Save anonymous/a605c4ac32e0800d71885b7952f5728d to your computer and use it in GitHub Desktop.
Save anonymous/a605c4ac32e0800d71885b7952f5728d to your computer and use it in GitHub Desktop.
<?php
if(isset($_POST['Fetch'])){
$file_names = "playlista.txt";
$current_names = file_get_contents($file_names);
echo nl2br($current_names);
}
if(isset($_POST['Save']) && !empty($_POST['textbox'])){
$file_names = "playlista.txt";
$current_names_onfile = file_get_contents($file_names);
$current_names = $_POST["textbox"];
$arr = explode("\r", $current_names);
foreach($arr as $name)
{
#remove line breaks
$name = preg_replace('/[\r\n]/m', '', $name);
#if the name doesn't exist on file stores it.
if (!preg_match("/^\b$name\b\$/m", $current_names_onfile)) {
file_put_contents("playlista.txt", PHP_EOL.$name, FILE_APPEND);
}else{
echo "$to juz jest dodane!<br />";
}
}
$file_names = "playlista.txt";
$current_names = file_get_contents($file_names);
echo nl2br($current_names);
}else if(isset($_POST['Save'])){
echo "wpisz coś!";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment