php regex how to remove duplicate strings -


here long string like"abc,adbc,abcf,abc,adbc,abcf"

i want use regex remove duplicate strings seperated comma

the following codes, result not expect.

$a='abc,adbc,abcf,abc,adbc,abcf'; $b=preg_replace('/(,[^,]+,)(?=.*?\1)/',',',','.$a.','); echo $b; 

output:,adbc,abc,adbc,abcf,

it should : ,abc,adbc,abcf,

please point problem. thanks.

you can tyr this-

$a='abc,adbc,abcf,abc,adbc,abcf';  $pieces = explode(",", $a); $unique_values = array_unique($pieces); $string = implode(",", $unique_values); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -