y mucho Stress ya es insertar 1 por 1 en una base de datos y tambien da stress limpiar con remplazar por del dreamweaver o del blog de notas...
luego pasar a excell y luego importar a mysql.. o como sea que lo hagan...
bue.. harto de tanto kilombo cree este programita y lo quiero compartir con ustedes...
Como extraer valores de <option value="id">texto</option> ?
Código PHP:
<?php
function ExtraerEnTabla($envio,$format1,$format2,$format3){
$basura=htmlentities($envio);
$pri=htmlentities($format1);
$sec=htmlentities($format2);
$ter=htmlentities($format3);
$Reemplazar = array($pri,$sec,$ter,'" selected>','" selected="selected">');
$Por = array("<tr><td>","</td><td>","</td></tr>","</td><td>","</td><td>");
$ResultadoNrodoc = str_replace($Reemplazar, $Por, $basura);
$listo=$ResultadoNrodoc;
return $listo;
}
function ExtraerEnSQL($envio,$bd,$tb,$c1,$c2,$format1,$format2,$format3){
$basura=htmlentities($envio);
$pri=htmlentities($format1);
$sec=htmlentities($format2);
$ter=htmlentities($format3);
$Reemplazar = array($pri,$sec,$ter,'" selected>','" selected="selected">');
$Por = array("INSERT INTO `$bd`.`$tb` (`$c1`,`$c2`) VALUES ('","','","');<br />","','","','");
$ResultadoNrodoc = str_replace($Reemplazar, $Por, $basura);
$listo=$ResultadoNrodoc;
return $listo;
}
$listo=ExtraerEnTabla($_POST['basura'],$_POST['format1'],$_POST['format2'],$_POST['format3']);
$listo2=ExtraerEnSQL($_POST['basura'],$_POST['bd'],$_POST['tb'],$_POST['c1'],$_POST['c2'],$_POST['format1'],$_POST['format2'],$_POST['format3']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Extractor de Valores de <option value=""></option></title>
<script>
function muestrasql(accion){
if(accion == "SI"){
document.getElementById('sql').style.display='';
}else{
document.getElementById('sql').style.display='none';
}
}
</script>
</head>
<body>
<div align="center"><form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
Extractor de: <option value="Valor">Nombre</option><label>
<p>
<textarea name="basura" cols="50" rows="6" id="basura"><?php if($_POST['basura'] != ""){ echo htmlentities($_POST['basura']); }else{ echo '<option value="Valor">Nombre</option>'; }?></textarea>
<br />
<br />
<strong>Formato Campo:</strong>
<label>
<input name="format1" type="text" id="format1" value="<?php if ($_POST['format1'] == ""){ ?><option value="<?php }else{ echo htmlentities($_POST['format1']); } ?>" size="18" />
ValorX </label>
<label>
<input name="format2" type="text" id="format2" value="<?php if ($_POST['format2'] == ""){ ?>"><?php }else{ echo htmlentities($_POST['format2']); } ?>" size="5" />
NombreX
</label>
<label>
<input name="format3" type="text" id="format3" value="<?php if ($_POST['format3'] == ""){ ?></option><?php }else{ echo htmlentities($_POST['format3']); } ?>" size="12" />
</label>
</p>
<p><strong>Formato Resultado:
</strong>
<input type="radio" name="formato" id="formatotabla" value="tabla" <?php if (!isset($_POST['MM_remove'])){ ?>checked="checked"<?php } ?><?php if(isset($_POST['MM_remove']) && ($_POST['formato'] == "tabla")){ ?>checked="checked"<?php } ?> onclick="muestrasql('NO');" />
Tabla
<input type="radio" name="formato" id="formatosql" value="sql" <?php if(isset($_POST['MM_remove']) && ($_POST['formato'] == "sql")){ ?>checked="checked"<?php } ?> onclick="muestrasql('SI');" />
SQL
<br />
<?php
$none="none";
if(isset($_POST['MM_remove']) && ($_POST['formato'] == "sql")){
$none="";
}
?>
</p>
<div id="sql" style="display:<?php echo $none; ?>;"> <strong>Base de datos:
</label>
<label><strong>
<input name="bd" type="text" id="bd" value="<?php if($_POST['bd'] == ""){ echo "BasedeDatos"; }else{ echo htmlentities($_POST['bd']); } ?>" />
</strong></label>
Tabla
<label>
<input name="tb" type="text" id="tb" value="<?php if($_POST['tb'] == ""){ echo "Tabla"; }else{ echo htmlentities($_POST['tb']); } ?>" />
</label>
<br />
Campo1
<label>
<input name="c1" type="text" id="c1" value="<?php if($_POST['c1'] == ""){ echo "Campo1"; }else{ echo htmlentities($_POST['c1']); } ?>" />
</label>
Campo2</strong>
<label>
<input type="text" name="c2" id="c2" value="<?php if($_POST['c2'] == ""){ echo "Campo2"; }else{ echo htmlentities($_POST['c2']); } ?>" />
</label>
<br /></div>
<br />
<label><input type="submit" name="button" id="button" value="Extraer Valores" />
</label>
<input type="hidden" name="MM_remove" id="MM_remove" value="form1" />
</form>
</div>
<hr />
<div align="center"><?php if(isset($_POST['MM_remove']) && ($_POST['formato'] == "tabla")){ ?><table border="1" width="400">
<tr><td bgcolor="#CCCCCC"><strong>Value=""</strong></td>
<td bgcolor="#CCCCCC"><strong>Option</strong></td>
</tr><?php echo $listo; ?></table><?php } ?>
<br /><br />
<?php if(isset($_POST['MM_remove']) && ($_POST['formato'] == "sql")){ ?>
<?php echo $listo2; ?>
<?php } ?>
</div>
</body>
</html>
1) para copiar y pegar a excell
2) para pegar como consulta mysql....
Si alguien le encuentra algun error o alguna mejora voy a agradecer que lo postee aqui...
saludos!