Re: Text Parser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux