How can I read and echo a specific column in a tab delimited text file. For example:
|Company Name | Address | Owner|
Above I only want to display all the data under Company Name column
Any idea? Thanks
read and echo a specific column in a tab delimited text file
Moderator: General Moderators
-
greedyisg00d
- Forum Commoner
- Posts: 42
- Joined: Thu Feb 12, 2009 2:48 am
Re: read and echo a specific column in a tab delimited text file
You can loop through the file and echo the company name like this:
Regards,
Robert
Code: Select all
// Get a file into an array.
$lines = file('/path/to/your/file.txt');
// Loop through our array, pull out the first element and print it
foreach ($lines as $line_num => $line) {
$lineArr = explode("|",$line);
echo "Company name is ".$lineArr[1]."<br>"; //it is 1, not 0, because the line starts with |
}
Robert