Gents,
I am processing a CSV (Comma Seperated Variables) record containing. in some cases further quoted commas. i.e:
1234,4567,"1,234",string
The quotes are supplied by the generating program and are there to indicate the encloded comma is not a field seperator. I can't seem to find a simple method to have PHP interpret it that way. I am trying to extract the fields (4 in example above). If I can eliminate the enclosed comma(s), EXPLODE will then work its magic. Any suggestions?
(This is easy in DCL!)
Many thanks
Paul
More help please - Strings this time
- beaudoin_p
- $ HELP
- Posts: 13
- Joined: Fri Oct 21, 2005 10:31 am
- Location: London UK
- WillemGrooters
- VMS Guru
- Posts: 59
- Joined: Wed Jul 20, 2005 10:17 am
- Location: Netherlands
- Contact:
Of course, the best solution is to prevent the problem to occur at all, so have the generating program use another character, or leave it out completely. If you are able to do that, I would go for that. Normally, it has no additional value but clearing up display. Adding a separator is often much easier than removing them
Another approach would be that if you simply extract by the comma's and repair afterwards. In your line, you would get:
1234
1234
"1
234"
1234
and next you would need to scan each value to start with quote, and adding all values up to the firsr value ending in quote to this one.
Here, it would mean
""1" + "234"" = "1234" (or "1,234" if you add a terminator as well in fron of any following value)
Hope this helpd - I'm not yet familiar with PHP...

Another approach would be that if you simply extract by the comma's and repair afterwards. In your line, you would get:
1234
1234
"1
234"
1234
and next you would need to scan each value to start with quote, and adding all values up to the firsr value ending in quote to this one.
Here, it would mean
""1" + "234"" = "1234" (or "1,234" if you add a terminator as well in fron of any following value)
Hope this helpd - I'm not yet familiar with PHP...
- beaudoin_p
- $ HELP
- Posts: 13
- Joined: Fri Oct 21, 2005 10:31 am
- Location: London UK
Thanks for the comment but I'm afraid, in the first instance, I can't control the input format - it is what the generating program gives and is not changeable. Having said that, I tried str_split (return each char to array element) but this does not exist in the VMS version of PHP (PHP 5 only) however preg_split with the appropriate params ($strarray = preg_split('//',$buffer.-1,PREG_SPLIT_NO_EMPTY);) should give the result. This function is documented as being part of PHP since V3 but I still get 'unrecognised function'. What gives?
Is there any wat to 'dump' php and determine what functions are supported?
Thanks
Paul
Is there any wat to 'dump' php and determine what functions are supported?
Thanks
Paul
- WillemGrooters
- VMS Guru
- Posts: 59
- Joined: Wed Jul 20, 2005 10:17 am
- Location: Netherlands
- Contact:
give me an example
Paul,
Can you do this using PHP4 on Linux or Windows, it ought to work on VMS as well. Just try it with a very basic program and gather the output on each system. If you can reproduce your problem on VMS (doesn't work there, where it does on other systems), I think HP should know. If you are registered with HP's ITRC (which has an OpenVMS forum as well) you may drop it there (or I can do so - just send me the example and output (ZIPPED, preferably)
One thing though: What webserver are you using on VMS? I know that there are some issues with PHP and SWS 1.3-1 (I'm still working getting my systems prepared for all new stuff
)
Can you do this using PHP4 on Linux or Windows, it ought to work on VMS as well. Just try it with a very basic program and gather the output on each system. If you can reproduce your problem on VMS (doesn't work there, where it does on other systems), I think HP should know. If you are registered with HP's ITRC (which has an OpenVMS forum as well) you may drop it there (or I can do so - just send me the example and output (ZIPPED, preferably)
One thing though: What webserver are you using on VMS? I know that there are some issues with PHP and SWS 1.3-1 (I'm still working getting my systems prepared for all new stuff

- beaudoin_p
- $ HELP
- Posts: 13
- Joined: Fri Oct 21, 2005 10:31 am
- Location: London UK
Gents,
Many thanks for your comments, I have the (now obvious) answer to the first question: The function I am trying to call (split_str) is PHP 5 only ...
IN the online version of the manual there is an example script which, when modified, does the trick however, I have now run into something even more basic:
Snipette:
print_r($strarray);
// for ($i=0; $i < $ccnt and $strarray[$i] != $quote; $i++);
for ($i=0; $i < $ccnt; $i++);
{
$strpstrn[]=$strarray[$i];
}
echo 'out = ';
print_r($strpstrn);
echo 'nexti = '.$i;
echo 'nextn = '.$n;
This produces a print of the input array (correct) and nothing in the output array. While I am actually trying to process each char (remove the commas between quotes), getting even this simple thing to go is causing suicidal tendencies...
Is this not the way to copy individual elements from array to array? If not what syntax shoud I use?
Again (and as always) many thanks for any suggestions.
Paul
Many thanks for your comments, I have the (now obvious) answer to the first question: The function I am trying to call (split_str) is PHP 5 only ...
IN the online version of the manual there is an example script which, when modified, does the trick however, I have now run into something even more basic:
Snipette:
print_r($strarray);
// for ($i=0; $i < $ccnt and $strarray[$i] != $quote; $i++);
for ($i=0; $i < $ccnt; $i++);
{
$strpstrn[]=$strarray[$i];
}
echo 'out = ';
print_r($strpstrn);
echo 'nexti = '.$i;
echo 'nextn = '.$n;
This produces a print of the input array (correct) and nothing in the output array. While I am actually trying to process each char (remove the commas between quotes), getting even this simple thing to go is causing suicidal tendencies...
Is this not the way to copy individual elements from array to array? If not what syntax shoud I use?
Again (and as always) many thanks for any suggestions.
Paul
- beaudoin_p
- $ HELP
- Posts: 13
- Joined: Fri Oct 21, 2005 10:31 am
- Location: London UK
Gents
I know it is bad form to answer your own post but it is necessary when admiting ignorance (and even stupidity) and to keep you from wasting time ...
My simple error in the posted code is the ; at the end of the FOR statement. This (apparently) causes the statement to not execute.
I will however continue to post questions here - I just hope they are a little less dumb
Paul
I know it is bad form to answer your own post but it is necessary when admiting ignorance (and even stupidity) and to keep you from wasting time ...
My simple error in the posted code is the ; at the end of the FOR statement. This (apparently) causes the statement to not execute.

I will however continue to post questions here - I just hope they are a little less dumb
Paul
- WillemGrooters
- VMS Guru
- Posts: 59
- Joined: Wed Jul 20, 2005 10:17 am
- Location: Netherlands
- Contact:
no problem
These are just things so easily overlooked. It happens once in a while (where while = {short..long} ) 

I realize this post is a little late, but there is a fuction that is built into PHP called fgetcsv(), which does what you were trying to do manually. And it know how to deal with embedded quotes.
Ken
Ken