Re: Text Parser

From: Date: Thu, 02 Dec 2004 15:42:38 +0000
Subject: Re: Text Parser
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-203352@lists.php.net to get a copy of this message
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


« previous php.general (#203352) next »