Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将行写入.csv或.txt文件php的限制_Php_File_Write - Fatal编程技术网

将行写入.csv或.txt文件php的限制

将行写入.csv或.txt文件php的限制,php,file,write,Php,File,Write,我使用fwrite php编写了一个将大量数据从excel转换为.txt或.csv的程序。然而,当我在放置数据的.txt文件上添加fread时,数据变成了虚线。我怎样才能修好它?此处附上从.txt或.csv突出显示的代码,以及以下代码:- **********我的代码************* for loop here { $split_filename_path = fopen($tempfile_path.$split_filename.$total_round.$extensio

我使用fwrite php编写了一个将大量数据从excel转换为.txt或.csv的程序。然而,当我在放置数据的.txt文件上添加fread时,数据变成了虚线。我怎样才能修好它?此处附上从.txt或.csv突出显示的代码,以及以下代码:-

**********我的代码*************

for loop here {
    $split_filename_path = fopen($tempfile_path.$split_filename.$total_round.$extension, "w");`
    $split_file_txt = $ISBN.$comma.$Title.$comma.$Qty.$comma.$Location.$comma.$outlet;
    fwrite($split_filename_path, $split_file_txt);
}
fclose($split_filename_path);
然后它来了 我的阅读代码*****

    $myfile = fopen($file, "r");
    $fread = fread($myfile,filesize($file));
        
    fclose($myfile);
    $split = explode("\n",$fread);
    $datafields = array('ISBN', 'title', 'qty', 'location', 'outlet');
    $insertvalues = array();
    foreach($split as $string){ 
        $row = explode(",",$string);
        $questionmarks[] = '(' . $this->placeholder('?',$irow, sizeof($row)) . ')'; 
        $insertvalues = array_merge( $insertvalues, array_values($row));
    }
    $sql = "INSERT INTO temp_data (".implode( ',', $datafields) . ") 
                VALUES ". implode( ',', $questionmarks);
    
    function placeholder( $text, $irow, $count = 0, $separator = ',' ) {
        $result = array();
        if ($count > 0) {
            for ($x = 0; $x < $count; $x++) {
                $result[] = $text;
            }
        }
        return implode($separator, $result);
    }
找到了答案。 $Title=preg_replace(“/\r |\n/”,“”,$Title)

9780794435295,BARBIE & HER SISTERS IN THE GREAT PUPPY ADVENTURE: (supposed to be full :- BARBIE & HER SISTERS IN THE GREAT PUPPY ADVENTURE: A SLIDING TAB BOOK BARBIE MOVIE TIEIN )