Hey everyone,
What function can I use to grab a .csv file from a remote webserver for
use in my PHP script. I want to do some parsing and statistical
analysis on it (server side).
What PHP function is used for this? I can't seem to find it in Google
or the online PHP manual, because I don't really know what keywords to
use.
Thank you very much
PulsarSL 5 5215 Pu******@gmail.com wrote: What function can I use to grab a .csv file from a remote webserver for use in my PHP script. I want to do some parsing and statistical analysis on it (server side).
Depends on how you want the remote data. Either file() or
file_get_contents() should do the trick. See documentation for more
details: http://www.php.net/file http://www.php.net/file_get_contents
Cheers,
NC
<?php
/* cvsParser.php Parse CSV file(s)
Copyright (C) 2005 Mustafa Y. Acikyildiz <yalcin at webliyacelebi dot
com>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free
Software Foundation; either version 2 of the License, or (at your
option)
any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along
with
this library; if not, write to the Free Software Foundation, Inc., 59
Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
$remoteFileAddr = "http://10.0.0.99/x.csv";
$content = file_get_contents($remoteFileAddr) or die ("error");
$seperator = ";";
$nPos = strpos($content,"\n");
$firstLine = substr($content, 0, $nPos);
// subtracting first line(column titles) from main content
$content = substr($content, $nPos, strlen($content));
$colNum = substr_count($firstLine, $seperator);
// Exploding First Line for Column titles
$tree = explode($seperator, $firstLine);
// Parsing Data
// Exploding content line by line
$lbl = explode("\n", $content);
$conCount = count($lbl);
foreach ($tree as $title) {
echo "$title \t";
}
echo "\n";
foreach ($lbl as $line) {
$i = 0;
// Exploding content with seperator
$cols = explode($seperator, $line);
foreach ($cols as $col) {
echo "$col \t";
$i++;
}
echo "\n";
}
?>
<?php
/* csvParser.php Parse CSV file(s)
Copyright (C) 2005 Mustafa Y. Acikyildiz <yalcin at webliyacelebi dot
com>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free
Software Foundation; either version 2 of the License, or (at your
option)
any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along
with
this library; if not, write to the Free Software Foundation, Inc., 59
Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
$remoteFileAddr = "http://10.0.0.99/x.csv";
$content = file_get_contents($remoteFileAddr) or die ("error");
$seperator = ";";
$nPos = strpos($content,"\n");
$firstLine = substr($content, 0, $nPos);
// subtracting first line(column titles) from main content
$content = substr($content, $nPos, strlen($content));
$colNum = substr_count($firstLine, $seperator);
// Exploding First Line for Column titles
$tree = explode($seperator, $firstLine);
// Parsing Data
// Exploding content line by line
$lbl = explode("\n", $content);
$conCount = count($lbl);
foreach ($tree as $title) {
echo "$title \t";
}
echo "\n";
foreach ($lbl as $line) {
$i = 0;
// Exploding content with seperator
$cols = explode($seperator, $line);
foreach ($cols as $col) {
echo "$col \t";
$i++;
}
echo "\n";
}
?>
Thanks everyone!
PulsarSL This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Peter A. Schott |
last post by:
Got a strange scenario going on here in that I could have sworn this worked
yesterday. I am issuing binary retrieval calls to an FTP server, writing to a
file, close the file, then removing the...
|
by: Lamberti Fabrizio |
last post by:
Hi all,
I've to access to a network file from an asp pages.
I've red a lot of things on old posts and on Microsoft article but I can't
still solve my problem.
I've got two server inside the...
|
by: Douglas Harber |
last post by:
If I have DB2 8.1 (FP5, I believe, but not relevant to my question...I hope)
installed on my desktop, do I have what I need to connect to a remote DB2
server (also running 8.1 FP5) from my desktop...
|
by: prodirect |
last post by:
Hi all,
I hope someone can help me. I've recently created a database and wanted to
put it up on an ftp sight so that multiple people could access the same
tables at the same time from different...
|
by: Jon L. Lovesky |
last post by:
Hello all,
I am attempting to access a remote folder from an asp.net application (all
within the same domain). The application is configured for windows
authentication in IIS and the asp.net...
| |
by: olekribu |
last post by:
Hi!
I'm struggling with the following scenario:
I want my asp.net application to be able to create and write to a specific file on a remote file server from a web server. Both servers have...
|
by: Jerim79 |
last post by:
Probably an incredibly simple answer, but I can't seem to phrase it so
a search engine can understand it.
I have a php script with a simple include:
include("/include_this.php")
I need to...
|
by: Noy B |
last post by:
Hi,
I have developed a small application that is using a MSAccess DB.
the problem is that it was developed on a machine where the
application and the DB are both located.
now it needs to be...
|
by: Usenet User |
last post by:
From a .NET 1.1 app: need to access a file share on a remote server by
its UNC path, i.e., \\server\folder\subfolder\, using specific
username and password.
The problem is that the credentials...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |