Created
September 22, 2016 21:59
-
-
Save anonymous/a605c4ac32e0800d71885b7952f5728d 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 | |
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