Page 1 of 1

Regarding Regular Expression in php

Posted: Sat Jul 11, 2009 2:52 pm
by varma457
Hi,

I had problem with using regular expression in php.
For example

$value="safdha","sfafha","safaff";

I am getting the above string from a file.I want individual values of a given string.Like safdha...
I used
preg_split("/\"(\s*)\"\,?",$value);

But I am not getting any result..
can any one help me regarding this..

Thanks in Advance..

Re: Regarding Regular Expression in php

Posted: Sat Jul 11, 2009 3:09 pm
by jackpf

Code: Select all

$str = '$value="a","b","c";';
preg_match_all('/\"(.*?)\"(\s)?(\,|\;)(\s)?/', $str, $matches);
print_r($matches);
Does that work?

Re: Regarding Regular Expression in php

Posted: Sat Jul 11, 2009 3:21 pm
by Darhazer
In this case, fgetcsv probably is the best solution
Additionally, you can try explode by "," string (with the quotes)

Re: Regarding Regular Expression in php

Posted: Sat Jul 11, 2009 5:11 pm
by varma457
it is not working..............

Re: Regarding Regular Expression in php

Posted: Sun Jul 12, 2009 12:27 am
by varma457
Thank you..I am appreciating your work...

Re: Regarding Regular Expression in php

Posted: Sun Jul 12, 2009 1:38 pm
by Darhazer
McInfo wrote: PHP 5.3.0 introduces the function str_getcsv() which can be used on $value like fgetcsv() is used on the contents of a file.
10x