PHP read the source of the Web page, export to TXT file, read xls, read the file name of all files under the folder

Source: Internet
Author: User

<?php

Read Web page source code
$curl = Curl_init ();
curl_setopt ($curl, Curlopt_url, $url);
curl_setopt ($curl, Curlopt_header, 1);
curl_setopt ($curl, Curlopt_returntransfer, 1);
curl_setopt ($curl, Curlopt_ssl_verifypeer, false);//This is the point.
$contents = curl_exec ($curl);


Export as TXT file
$str = "ABCD";
$FP =fopen ("Pic.txt", "w");
Fputs ($fp, $STR);
Fclose ($FP);


Read table
Require_once ' excel_reader2.php ';
$data = new Spreadsheet_excel_reader ();
$data->setoutputencoding (' UTF-8 ');
$data->read ($filename);
for ($i =1; $i <= $data->sheets[0]["NumRows"]; $i + +) {
for ($j =1; $j <= $data->sheets[0][' numcols '); $j + +) {
[Email protected] $data->sheets[0][' cells ' [$i] [$j];
}
}

Read the file name of all files under the folder
$filedir = "c:/users/xia/desktop/new Folder/productinfolist/";
$rfdir = new Rdfile ($filedir);
$file = Implode ("\ r \ n", $rfdir->filelist);
Class rdfile{
Public $fileList; File names for all sub-folders
Public $ftype; Restricting the type of file
Public $dirlist; All file and folder names under the current folder.
function __construct ($path, $filetype = "*") {
if (!is_dir ($path)) {die ("This is not a directory");}
$len = strlen ($path)-1;
if ($path {$len} = = "/" | | $path {$len} = = "\") {$path = substr ($path, 0,-1);}
$this->ftype = $filetype;
$this->filelist = Array ();
$this->readypath ($path);
}
Public Function Readypath ($path) {
$dirList = Scandir ($path);
unset ($dirList [0]);
Unset ($dirList [1]);
$this->dirlist = $dirList;
foreach ($dirList as $key = = $value) {
$pathfile = $path. Directory_separator. $value;
if (Is_dir ($pathfile)) {
$this->readypath ($pathfile);
}else if (Is_file ($pathfile)) {
if ($this->ftype== "*") {
$this->filelist[] = $pathfile;
}else{
if (STRRCHR ($pathfile, ".") == ".". $this->ftype) {$this->filelist[] = $pathfile;}
}
}
}
}
}

?>

PHP read the source of the Web page, export to TXT file, read xls, read the file name of all files under the folder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.