Stereofenix
New Member
I'm loading a select options from a txt file, but when I do an explode to split a string by commas, that make me an option whose valuehttp://stackoverflow.com/questions/15577139/= "". How can I avoid this?HTML\[code\]<body> Grupo musical<select id="selGrup" > <option value='http://stackoverflow.com/questions/15577139/0' selected>Seleccione grupo</option> <option value='http://stackoverflow.com/questions/15577139/1'>ACDC</option> <option value='http://stackoverflow.com/questions/15577139/2'>Queen</option> <option value='http://stackoverflow.com/questions/15577139/3'>Zeppelin</option> </select><br> <select id="selCanc"></select></body>\[/code\]JS\[code\]<script> $('#selGrup').change(function(){ var grupo = $("#selGrup").val(); if(grupo==0){ $( "#dialog" ).dialog( "open" ); } else{ $.ajax({type: "POST", url: "pr03LlenaCanciones.php", data: "grupo="+grupo, success:function(data) { respuesta=$.parseJSON(data); $('#selCanc').html(respuesta.salida); console.log(respuesta.mensaje); } }); } });</script>\[/code\]TXT file structure (example):\[code\]Highway to hell,http://www.youtube.com/watch?v=YJQp7Id2ywEThunderstruck,http://www.youtube.com/watch?v=v2AC41dglnM\[/code\]PHP\[code\]ini_set('error_reporting', E_ALL ^ E_NOTICE);ini_set('display_errors','on'); ob_start();if($_POST['grupo']==1) { $file = fopen("txt/acdc.txt", "r") or exit("Unable to open file!"); //Output a line of the file until the end is reached while(!feof($file)){ $cadena= fgets($file); $res=explode(",",$cadena); echo '<option value="'.$res[0].'">'.$res[1].'</option>'; echo '<option value="'.$res[2].'">'.$res[3].'</option>'; } fclose($file); $salida=ob_get_contents(); ob_end_clean(); $mensaje="Toda va ok"; $aValores=array('salida'=> $salida,'mensaje'=>$mensaje,'orden'=>$orden); echo json_encode($aValores); }\[/code\]