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 5249 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_conten ts() 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_conten ts($remoteFileA ddr) 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($f irstLine, $seperator);
// Exploding First Line for Column titles
$tree = explode($sepera tor, $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($sepera tor, $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_conten ts($remoteFileA ddr) 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($f irstLine, $seperator);
// Exploding First Line for Column titles
$tree = explode($sepera tor, $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($sepera tor, $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 file from the remote site. When I do
this, I end up with 0 byte files. I was hoping to avoid parsing a list of
remote and local files and matching them up that way because it would be easier
to remove on successful retrieve. I'm including some...
|
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 same NT domain, each one has its own web
server.
The web server is always IIS 5.0.
|
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 machine? I assume, perhaps
naively, that all the parts are there but I've spent several hours trying to
grasp how to go about accessing the remote server.
Specifically, I'm trying to create and populate databases on the remote
server from...
|
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 geographical locations. I have been
completely unsucessful in acheiving this goal so far however.
Things I have tried:
Create a shortcut to ftp sight via browser then tried to map local drive to
|
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 worker process runs as the local
ASP.NET account. When the application is about to access the remote folder I
switch the security context to the remote user programmatically, then switch
it back afterwards. When I run the application on my local...
| |
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 Windows Server 2003 with IIS 6.0 installed.
What I have done is:
1. I have created 2 identical accounts on the servers, a "Custom ASP.NET account" by following this "How To":
|
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 edit this so it accesses the file from another server. I
have tried:
include("http://192.168.1.1/include_this.php:)
|
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 change that the application will be able to run on
any other machine (using \\ syntax on the run command- not a problem)
using the DB located on a static-different machine.
for this purpose I need to create a Remote Connection from my
|
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 are local to the remote server.
Therefore, impersonating that user when accessing the share is not
possible.
One solution is to map a network drive using the credentials, but it
seems kind of ugly and old school.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |