/**
* Take a comma separated string and place double quotes around each value.
* @param String $string comma separated string, eg 'alpha,beta,charlie'
* @return String comma separated, quoted values, eg '"alpha","beta","charlie"'
*/
function addQuote($string)
{
$array = explode(',', $string);
$newArray = array();
foreach($array as $value)
{
$newArray[] = '"' . $value . '"';
}
$newString = implode(',', $newArray);
return $newString;
}
echo addQuote('alpha,beta,charlie'); // results in: "alpha","beta","charlie"
fonte
2012-07-05 08:59:59
Perché le restrizioni? – SpacedMonkey
Non voglio avere più linee di codice per eseguire questo. Ho pensato che ci potesse essere una funzione integrata in php per fare questo – neeraj