Richard Davey wrote:
Hello Pablo,

Thursday, December 2, 2004, 3:12:09 PM, you wrote:

PDM> Iīm receiving this: "house , ball , door , roof , floor"
PDM> And I want to obtain this: "'house','ball','door','roof','floor'"

PDM> Maybe, I should use implode or explode, but I just canīt figure out how..
PDM> Help?
$parts = explode(',', $original);
$parts = array_map('trim', $parts);
$new = "'".implode("','", $parts)."'";

You could explode it, loop it, etc etc - but if the data always follows that format and is trust-worthy, the following is probably quicker:

$old_data = "house,ball,door,roof,floor";
$data = "'" . str_replace("," , "','" , $old_data) . "'";

At least, I can't see why this won't work :)

If your data has all those extra spaces in, then just amend the
str_replace accordingly.

Best regards,

Richard Davey

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to