Beispiel #1
0
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";
}
Beispiel #2
0
var_dump($split);
/*
 * str_replace   
 * String change
 * String replace
 * String input
 *  */
function convert_chars_to_entities($str)
{
    $str = str_replace('À', '&#192;', $str);
    $str = str_replace('Á', '&#193;', $str);
    $str = str_replace('Â', '&#194;', $str);
    $str = str_replace('Ã', '&#195;', $str);
    $str = str_replace('Ä', '&#196;', $str);
    $str = str_replace('Ø', '&#216;', $str);
    $str = str_replace('Ù', '&#217;', $str);
    $str = str_replace('Ú', '&#218;', $str);
    $str = str_replace('Û', '&#219;', $str);
    $str = str_replace('Ü', '&#220;', $str);
    $str = str_replace('Ý', '&#221;', $str);
    $str = str_replace('Þ', '&#222;', $str);
    $str = str_replace('ß', '&#223;', $str);
    $str = str_replace('à', '&#224;', $str);
    $str = str_replace('á', '&#225;', $str);
    $str = str_replace('â', '&#226;', $str);
    $str = str_replace('ã', '&#227;', $str);
    return $str;
}
$str = 'adadada131313&#216;';
echo convert_chars_to_entities($str);