problem with explode and double quotes
Posted: Sat Oct 10, 2009 5:32 am
Hi all,
I have a problem with explode() when receivng a string which includes double quotes that I want to maintain.
I read a line ($line) from a file. $line contains the following:
dato1, dato2, "dato3.1,dato3.2", dato4
Then I realize the explode:
$regis= explode(",", $line);
If I print the result I obtain the following:
$regis[0]=dato1
$regis[1]=dato2
$regis[2]="dato3.1
$regis[3]=dato3.2"
$regis[4]=dato4
But what I really want to obtain is the following:
$regis[0]=dato1
$regis[1]=dato2
$regis[2]="dato3.1,dato3.2" (with or without double quotes, It doesnt matter)
$regis[3]=dato4
I cant change the comas as split character becuase this file is generated by other application.
Do you have any idea?
Thanks and regards.
I have a problem with explode() when receivng a string which includes double quotes that I want to maintain.
I read a line ($line) from a file. $line contains the following:
dato1, dato2, "dato3.1,dato3.2", dato4
Then I realize the explode:
$regis= explode(",", $line);
If I print the result I obtain the following:
$regis[0]=dato1
$regis[1]=dato2
$regis[2]="dato3.1
$regis[3]=dato3.2"
$regis[4]=dato4
But what I really want to obtain is the following:
$regis[0]=dato1
$regis[1]=dato2
$regis[2]="dato3.1,dato3.2" (with or without double quotes, It doesnt matter)
$regis[3]=dato4
I cant change the comas as split character becuase this file is generated by other application.
Do you have any idea?
Thanks and regards.