473,830 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing CSV File for PHP Parsing from Remote Server

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

Dec 15 '05 #1
5 5249
NC
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

Dec 16 '05 #2
<?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";
}
?>

Dec 16 '05 #3
<?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";
}
?>

Dec 16 '05 #4
On 15 Dec 2005 15:26:37 -0800, 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).

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.


http://uk.php.net/fgetcsv
--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 16 '05 #5
Thanks everyone!

PulsarSL

Dec 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1843
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...
23
2920
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.
2
7080
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...
3
4322
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
2
2905
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...
2
5704
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":
1
1456
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:)
4
4228
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
1
5480
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.
0
9791
marktang
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...
0
9642
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,...
0
10771
Oralloy
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...
0
10487
jinu1996
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...
0
10202
tracyyun
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...
0
9313
agi2029
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...
1
7745
isladogs
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...
0
5617
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...
2
3958
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.