Regarding Regular Expression in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
varma457
Forum Newbie
Posts: 23
Joined: Sat Jul 11, 2009 2:43 pm

Regarding Regular Expression in php

Post 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..
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Regarding Regular Expression in php

Post by jackpf »

Code: Select all

$str = '$value="a","b","c";';
preg_match_all('/\"(.*?)\"(\s)?(\,|\;)(\s)?/', $str, $matches);
print_r($matches);
Does that work?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Regarding Regular Expression in php

Post by Darhazer »

In this case, fgetcsv probably is the best solution
Additionally, you can try explode by "," string (with the quotes)
varma457
Forum Newbie
Posts: 23
Joined: Sat Jul 11, 2009 2:43 pm

Re: Regarding Regular Expression in php

Post by varma457 »

it is not working..............
varma457
Forum Newbie
Posts: 23
Joined: Sat Jul 11, 2009 2:43 pm

Re: Regarding Regular Expression in php

Post by varma457 »

Thank you..I am appreciating your work...
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Regarding Regular Expression in php

Post 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
Post Reply