Say I have an file whose contents are as follows:
"test","com,ma","food"
How would I go about turning that file into an array, as follows?:
$file_contents = array('"test"','"com,ma"','"food"');
Doing explode(',',$file_contents) wouldn't be sufficient because the
resultant array would have four entries - not three - and would instead
read like this:
$file_contents = array('"test"','"com','ma"','"food"');
I could probably iterate through each character within the array, but
that, it seems to me, would be inefficient. Plus, it'd require more
code that'd be nice to avoid.
So, anyway, any ideas? 3 2280
I should, perhaps, also mention that strings aren't the only things
that can be between the commas. Another valid file is as follows:
"te,st",4,2
Given this, the regular expression is, at the very least, not going to
be particuraly easy. Before making the original post, I was unable to
come up with a sufficient one for preg_split.
As such, if regular expressions are the key, I could still use some
help...
yawnmoth said the following on 02/11/2005 01:52: I should, perhaps, also mention that strings aren't the only things that can be between the commas. Another valid file is as follows:
"te,st",4,2
Given this, the regular expression is, at the very least, not going to be particuraly easy. Before making the original post, I was unable to come up with a sufficient one for preg_split.
As such, if regular expressions are the key, I could still use some help...
A shortcut might be http://php.net/fgetcsv.
--
Oli This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Deepa |
last post by:
I am writing a console app in c# wherein am converting a dataset into a CSV
file. It works fine. But I have some values in the dataset which have a comma
within(eg. A,B,C). When I view the CSV file...
|
by: Ron McCafferty |
last post by:
How do you read comma delimited data from programs such as Excel where the
data itself contains dounble quotes and commas. It used to be you could just
use input. How is it fone now?
The data...
|
by: Elmo Watson |
last post by:
I've been asked to develop a semi-automated type situation where we have a
database table (sql server) and periodically, there will be a comma
delimited file from which we need to import the data,...
|
by: SteelDetailer |
last post by:
Thnaks in advance for considering this post. It's probably very simple,
but.....
I have an old VB6 application that allows me to create, save and edit a
"project information file" that is a...
|
by: Kim Bundgaard |
last post by:
Hi
Any suggestion would be fine.
I have installed DB2 Connect EE V8.1 (fixpak 4) at two different Windows
2000 Servers, both have the same regional settings.
I am connecting to the same DB2...
|
by: John B. Lorenz |
last post by:
I'm attempting to write an input routine that reads from a comma delimited
file. I need to read in one record at a time, assign each field to a field
array and then continue with my normal...
|
by: Serve Laurijssen |
last post by:
Is code like the following allowed? I am talking about the comma after the
last function in the initializer.
void f(void) {puts("f");}
void g(void) {puts("g");}
struct Funcs { void...
|
by: Wayne |
last post by:
I have the following string:
"smith", "Joe", "West Palm Beach, Fl."
I need to split this string based on the commas, but as you see the city
state contains a comma. String.split will spilt the...
|
by: =?Utf-8?B?RXJpY2E=?= |
last post by:
I am trying to dynamically create a javascript link. But, I get the following
error:
BC32017: Comma, ')', or a valid expression continuation expected.
Here is the line I try creating the...
|
by: Arnold |
last post by:
Hi there,
In a textbox containing a string of ID numbers each separated by a
comma, how can I keep only the first value, and then remove all of the
other numbers and commas behind it? The first...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |