Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Comma Separated Value to Double Quotes comma separated string

I have a comma separated value like

alpha,beta,charlie

how can i convert it to

"alpha","beta","charlie"

using a single funcion of php without using str_replace?

like image 862
neeraj Avatar asked Jul 05 '12 08:07

neeraj


1 Answers

Alternatively to Richard Parnaby-King's function (shorter):

function addQuotes($string) {
    return '"'. implode('","', explode(',', $string)) .'"';
}

echo addQuotes('alpha,beta,charlie'); // = "alpha","beta","charlie"
like image 105
jexact Avatar answered Oct 31 '22 00:10

jexact