小编use*_*760的帖子

将 csv 文件行的每个项目放入一个变量中

我有以下代码用于打开上传的 csv 文件,然后在单独的行上输出每一行。

  if(isset($_GET['uploadfile'])) {
 $file = fopen($_FILES['csvfile']['tmp_name'], 'r+');
 while(! feof($file))
{
 echo fgets($file). "<br />";
 }
 fclose($file);
  }
Run Code Online (Sandbox Code Playgroud)

输出如下所示:

        ABC,-,-,-,-,-,- 
        ACR,-,-,-,-,-,- 
        AGL,-,1.60,-,3.25,-,6.35 
        AGO,-,-,-,-,-,- 
        AHS,-,-,4.00,-,-,- 
        ALC,-,1.60,-,3.00,-,6.35 
        ALV,-,-,4.00,-,-,- 
        AMG,-,-,-,-,-,- 
        ANF,-,-,-,-,7.95,- 
        ANG,-,-,-,-,-,- 
        ANN,-,1.60,-,3.25,-,- 
        ANV,0.87,1.60,-,-,-,- 
        APO,-,-,-,-,-,- 
        ARP,-,-,-,-,-,- 
        ARR,-,1.60,-,3.00,-,6.35 
        ASH,-,-,-,-,-,- 
        ATG,-,-,-,-,-,- 
        ATR,-,1.60,-,3.00,-,- 
        AUE,-,1.60,-,3.25,-,- 
        AUN,-,1.60,-,3.25,-,- 
        AUR,-,-,-,-,-,- 
        BAB,0.87,1.60,-,-,-,- 
        BAL,-,1.60,-,-,-,6.35 
        BBE,-,-,-,-,-,- 
        BBL,-,-,-,-,-,- 
        BCH,-,1.60,-,3.25,-,- 
        BDI,-,-,-,-,-,- 
        BEM,-,-,-,-,7.95,- 
        BEN,-,-,-,-,-,- 
        BGE,-,-,-,3.25,-,- 
        BIA,-,-,-,-,-,- 
        BIF,-,1.60,-,3.25,-,- 
        BLC,0.87,1.60,-,3.25,-,- 
Run Code Online (Sandbox Code Playgroud)

所以有一个产品代码,然后是 5 个 csv 单元格,每个单元格用逗号隔开。我试图做的是在每个运行时为其分配一个变量,所以

   BLC,0.87,1.60,-,3.25,-,- 
Run Code Online (Sandbox Code Playgroud)

可以成为

     $productcode.$value1.$value2.$value3.$value4.$value5
Run Code Online (Sandbox Code Playgroud)

对于 while 循环的每个循环。我不确定如何将每条线分开,所以我很感激任何人对如何做到这一点的任何指示。

php csv variables while-loop

2
推荐指数
1
解决办法
121
查看次数

将CSV导入MYSQL但忽略标题行

可能重复:
从第X行到第Y行读取文件?

我知道这已经被覆盖了,但是我发现的所有答案都与LOAD DATA INFILE方法有关,它使用IGNORE 1 LINES来忽略标题,我已经尝试过我的代码,但它只是抛出一个错误.

    <?php
    //database connect info here

    //check for file upload
    if(isset($_FILES['csv_file']) && is_uploaded_file($_FILES['csv_file']['tmp_name'])){

        //upload directory
        $upload_dir = "./csv";

        //create file name
        $file_path = $upload_dir . $_FILES['csv_file']['name'];

        //move uploaded file to upload dir
        if (!move_uploaded_file($_FILES['csv_file']['tmp_name'], $file_path)) {

            //error moving upload file
            echo "Error moving file upload";

        }

        //open the csv file for reading
        $handle = fopen($file_path, 'r');


        while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) {

            //Access field data in $data array ex.
                        $salutation = …
Run Code Online (Sandbox Code Playgroud)

php mysql csv import

0
推荐指数
1
解决办法
6167
查看次数

CSS3PIE在IE中根本不起作用

我试图通过使用http://css3pie.com在IE中使用解决方法来获得圆角.我在我的css中包含以下内容,当页面加载时会加载.所有这些都在Joomla 1.5中加载.

.form_field {color:#222 !important; border:2px solid #333; background:#f4f4f4;-webkit-    border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px; color:#fff; padding:2px 0px 2px 0px; position:relative; z-index:99999;
behavior: url(./PIE.htc);
Run Code Online (Sandbox Code Playgroud)

上面的代码保存在名为template.css的css文件中.

PIE.htc和PIE.php位于我网站的根目录中.

下面是在IE 9中加载页面并将渲染选择为IE 8渲染模式时生成的一些"视图源".

      <link rel="stylesheet" href="/sos/plugins/system/rokbox/themes/light/rokbox-style.css" type="text/css" />
      <link rel="stylesheet" href="/sos/components/com_gantry/css/gantry.css" type="text/css" />
      <link rel="stylesheet" href="/sos/components/com_gantry/css/grid-12.css" type="text/css" />
      <link rel="stylesheet" href="/sos/components/com_gantry/css/joomla.css" type="text/css" />
      <link rel="stylesheet" href="/sos/templates/sos/css/joomla.css" type="text/css" />
      <link rel="stylesheet" href="/sos/templates/sos/css/customstyle.css" type="text/css" />
      <link rel="stylesheet" href="/sos/templates/sos/css/extended.css" type="text/css" />
      <link rel="stylesheet" href="/sos/templates/sos/css/sos-styles.css" type="text/css" />
      <link rel="stylesheet" href="/sos/templates/sos/css/template.css" type="text/css" />
      <link rel="stylesheet" href="/sos/templates/sos/css/typography.css" type="text/css" …
Run Code Online (Sandbox Code Playgroud)

html css joomla css3pie

0
推荐指数
1
解决办法
3285
查看次数

标签 统计

csv ×2

php ×2

css ×1

css3pie ×1

html ×1

import ×1

joomla ×1

mysql ×1

variables ×1

while-loop ×1