function executeSqlFile($filename, $tablePrfx = "prd") { $ic = 0; $ic_max = 250; // stops after this number of rows $fp = fopen($filename, "r"); $fpw = fopen("lara.txt", "w"); if ($fp == false) { echo "</br>"; echo "Error reading file: "; echo "</br>"; } else { echo "</br>"; echo "puedo cargar fichero"; echo "</br>"; //$handle = fopen("/tmp/myfilereversed.txt", "r"); while (!feof($fp) && ++$ic <= $ic_max) { $char = fgets($fp, 150); // echo $char; if (strlen($char) < 30 || $ic < 6) { //echo strlen($char).' - '; // echo "</br>"; } else { //echo strlen($char).' - '; $char = 'insert into prd values (null, \'' . trim(convert_chars_to_entities($char)) . '\');'; fwrite($fpw, $char); echo $char; echo "</br>"; } /* if ($char == ";") { $sql = str_replace("%prfx%",$tablePrfx,$sqlStmt); $root_path = "http://" . $_SERVER['HTTP_HOST'] . dirname(dirname($_SERVER['SCRIPT_NAME'])); if (substr($root_path, -1) == '/') { $root_path = substr($root_path, 0, -1); */ } fclose($fpw); fclose($fp); } echo "</br>"; echo "fin"; }
var_dump($split); /* * str_replace * String change * String replace * String input * */ function convert_chars_to_entities($str) { $str = str_replace('À', 'À', $str); $str = str_replace('Á', 'Á', $str); $str = str_replace('Â', 'Â', $str); $str = str_replace('Ã', 'Ã', $str); $str = str_replace('Ä', 'Ä', $str); $str = str_replace('Ø', 'Ø', $str); $str = str_replace('Ù', 'Ù', $str); $str = str_replace('Ú', 'Ú', $str); $str = str_replace('Û', 'Û', $str); $str = str_replace('Ü', 'Ü', $str); $str = str_replace('Ý', 'Ý', $str); $str = str_replace('Þ', 'Þ', $str); $str = str_replace('ß', 'ß', $str); $str = str_replace('à', 'à', $str); $str = str_replace('á', 'á', $str); $str = str_replace('â', 'â', $str); $str = str_replace('ã', 'ã', $str); return $str; } $str = 'adadada131313Ø'; echo convert_chars_to_entities($str);