nee*_*raj 6 php string double comma
我有一个逗号分隔值,如
alpha,beta,charlie
Run Code Online (Sandbox Code Playgroud)
我怎么能把它转换成
"alpha","beta","charlie"
Run Code Online (Sandbox Code Playgroud)
使用单个功能的PHP而不使用str_replace?
jex*_*act 14
另外还有Richard Parnaby-King的功能(更短):
function addQuotes($string) {
return '"'. implode('","', explode(',', $string)) .'"';
}
echo addQuotes('alpha,beta,charlie'); // = "alpha","beta","charlie"
Run Code Online (Sandbox Code Playgroud)