Reply to Re: Accessing CSV File for PHP Parsing from Remote Server

Your name:

Reply:


Posted by Mustafa Yalcin Acikyildiz on 12/16/05 14:21

<?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";
}
?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация