使用PHP从excel解析数据

I try to make a simple function to get data from an Excel file (csv and xlsx) this is the structure of the documents

  • Date
  • Title
  • URL

After getting data from files the function will get the content of the url column and get his html content by file_get_content()

The problem is the function support only csv files, and file_get_content() gets only the content of URL finished by a name of files :

Example www.aaa.com/index.php

For this url www.aaa.com/index it make an error :

This the code of my function :

function getFileFromUrlExel($file){
    $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
    if( $ext == "csv" || $ext == "xslx"  ){
        $fp = fopen($file, "r");
        $columnnames = fgetcsv($fp, 1024);
        while (true == ($columns = fgetcsv($fp))) {
            $row = array_combine($columnnames, $columns);
            if($row["URL"] != ""){ $content = file_get_contents($row["URL"]); }else{ $content = "no_content"; }
            if($row["title"] != ""){ $name = $row["title"]; }else{ $name= "no_name"; }
            file_put_contents("files/".$row["title"].".html", $content);
        }
    }
}