RE: splitting string

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

 



Nov 16 at 12:00pm, Chris W. Parker wrote:
> > Also, is there actially better way to do this then adding \n between
> > strings? (e.g. store form fields name, address, city, state, zip,
> > phone, email as a one string in db and later pull them from DB and
> > split them back?)
> 
> Yes.
> $string = "$string1|$string2|$string3|$string4|$string5";
> $string_back = explode("|", $string);

I think tabs are a better delimiter since they can't really be input into
a text field in a typical form/browser, and they have even less relevance
to most text input. (I can't think of why a pipe would be there either,
but it would be easy to type one in, even on accident, therefore you'd
need to sanitize the input to assure you didn't have unexpected
delimiters; probably should anyway regardless of delimiter).

Also, remember list() when unpacking an array to variables:
list($address, $city, $state, $zip, $country) = explode("\t", $input);

I agree, however, that this is an undesirable way to store data in an 
RDBMS. Still, it's better than serializing and unserializing... :)

On that note, I think this should only be used for data that is NEVER
intended to be queried, but may be usefully extracted on SELECTed records. 
And we know the wisdom of assuming something will NEVER be necessary! :)

-- 
Kelly Hallman
// Ultrafancy

-- 
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