A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Parsing Character Delimited Files into Arrays
In this tutorial you will learn how to parse a multiple-line character delimited text file into a two dimensional array using PHP.
On Wednesday, September 19th 2007 at 10:52 PM
By Andrew Pociu (View Profile)
(Rated 2.7 with 9 votes)
A B C D E F G H IAs you can see there are two types of delimitations here. There are the lines, that are being delimited by a new line character ("\r\n" in Windows, "\n" in Unix), and then in each line, the values are being delimited by a tab ("\t"). In our code we're first going to delimit the file into lines, and while we loop through those lines we split each value apart using the explode() function. This will create a second dimesion to the array where the values are being stored.
Let's start with the first part, preparing the variables:
// This is what the sample file contains:
// File location (URL or server path)
The final lines of code will just extract three sample values from our newly created array for demonstration purposes:
// Will return A
echo "First row, first column: ".$Data."<br />";
// Will return E
echo "Second row, second column: ".$Data."<br />";
// Will return G
echo "Third row, first column: ".$Data."<br />";
The beauty of this code is its simplicity and the minimum need of modification in order to adapt it to your own needs. It has no set limits for the number of rows or columns that the array can hold, and no need to specify the size of the array.
|Digg It! Del.icio.us Reddit StumbleIt Newsvine Furl BlinkList|
Rate this tutorial
There are no related tutorials.
Related Source Code
There is no related source code.
PHP Job Search