I'm creating a music player. But the PHP just messes up filenames that have a singlequote in it. How can I fix this?
The first code is my current PHP. The second code is how i want the output to be.
// integer starts at 0 before counting
$i = 0;
$dir = 'music/';
if ($handle = opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if (!in_array($file, array('.', '..')) && !is_dir($dir.$file))
echo "<span class='song' id='".$file."' onClick='playSong(\"".addslashes($file)."\");'>".$file."</span><br />";
}
}
At first I did HTML, But now I want to use PHP so i can just drag songs into a folder and they get automaticly added to the list.
This is how the HTML was, which is how I want the output from the PHP to be.
<span id="Martin Garrix - Animals" onClick="playSong('Martin Garrix - Animals');">Martin Garrix - Animals</span>
<br />
<span id="TryHardNinja - Doin' it grand" onClick="playSong('TryHardNinja - Doin\' it grand');">TryHardNinja - Doin' it grand</span>
<br />
<span id="TryHardNinja - Calling All Ghosts" onClick="playSong('TryHardNinja - Calling All Ghosts');">TryHardNinja - Calling All Ghosts</span>