Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2007, 11:40 PM
Registered User
 
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default delimited files using PHP

Trying to read a comma delimited file in PHP. Below is what I have so far. Can't seem to get it to print the contents of the file, before or after the separation.
I am new at this and am trying to separate this file as part of a small project I'm working on. I need this piece of the puzzle, though.
Thanks

<?php
$filename = "c:\commafile.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, "25");
fclose ($fd);
$delimiter = ",";
$splitcontents = explode($delimiter, $contents);
$counter = "";
?>

 Complete File Contents


<?
echo $contents;
?>

<br> <br>
 Split File Contents


<?
foreach( $splitcontents as $color)
{
$counter = $counter+1;
echo "<b>Split $counter: </b> $colorn<br>";
}
?>






Similar Threads
Thread Thread Starter Forum Replies Last Post
XHTML in .php Files dimo414 Beginning PHP 4 February 27th, 2006 05:44 AM
uploading PHP files Adam H-W Beginning PHP 1 January 20th, 2006 02:06 AM
.php files vs .html files pbuongiovanni PHP How-To 2 January 5th, 2006 04:15 AM
Problem running php files on IIS sami1925 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 September 14th, 2005 09:41 AM
Comma delimited text files bmurrin Beginning VB 6 8 February 26th, 2004 02:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.