RE: [PHP] splitting string

2004-11-16 Thread Chris W. Parker
M. Sokolewicz on Tuesday, November 16, 2004 12:47 PM said: >> Chris W. Parker wrote: >> >>> Yes. >>> >>> $string = "$string1|$string2|$string3|$string4|$string5"; >>> >>> >>> $string_back = explode("|", $string); >>> > please explain... WHY is that better? Wel

RE: [PHP] splitting string

2004-11-16 Thread Mike
eone entering a single pipe to screw up the code or to just make it that much easier to find in large strings of text. -M -Original Message- From: John Nichel [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 16, 2004 4:29 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] splitting string M. S

RE: [PHP] splitting string

2004-11-16 Thread Kelly Hallman
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 =

Re: [PHP] splitting string

2004-11-16 Thread Afan Pasalic
Jason Wong wrote: You're not using your database like it should be used. Each invidually identifiable item should be stored in a separate column. Lumping everything into one column makes it harder to extract and process data. Google for "normalise table tutorial", or "normalize table tutorial" i

Re: [PHP] splitting string

2004-11-16 Thread Afan Pasalic
Chris W. Parker wrote: Yes. $string = "$string1|$string2|$string3|$string4|$string5"; $string_back = explode("|", $string); Ok, I'm going to change the code and use pipes :) Thanks to all of you.! -afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/uns

Re: [PHP] splitting string

2004-11-16 Thread Philip Thompson
On Nov 16, 2004, at 2:46 PM, M. Sokolewicz wrote: Afan Pasalic wrote: Chris W. Parker wrote: Yes. $string = "$string1|$string2|$string3|$string4|$string5"; $string_back = explode("|", $string); Ok, I'm going to change the code and use pipes :) Thanks to all of you.! -afan please explain... WHY is

RE: [PHP] splitting string

2004-11-16 Thread Chris W. Parker
Afan Pasalic on Tuesday, November 16, 2004 10:01 AM said: > I create a string from other strings: > $string = > $string1."\n".$string2."\n".$string3."\n".$string4."\n".$string5; and > then store it in DB. [snip] > Also, is there actially better way to do this the

Re: [PHP] splitting string

2004-11-16 Thread John Nichel
M. Sokolewicz wrote: please explain... WHY is that better? For me, I'll use pipes because they are so rarely used (if ever) when an user is entering text. If I make my delimiter a newline (or comma, etc.), and an end user enters one with whatever they're inputting, it will screw up my split.

Re: [PHP] splitting string

2004-11-16 Thread Dennis Lahay
Remember, working code is better than pretty code, on any day. If you have a system that you understand and it works (without excessively slowing the system down or grinding it to a halt), then stick with it. Over time you'll learn better ways of doing things. But, your first goal should be gett

Re: [PHP] splitting string

2004-11-16 Thread Brent Baisley
The problem is that you are using single quotes, so php is looking for a literal \n rather than escaping it to a new line character. Try double quotes and then PHP will parse the contents of the quotes, looking for escape characters and variables. explode("\n") Use nl2br() to convert new lines

Re: [PHP] splitting string

2004-11-16 Thread Afan Pasalic
That was the trick? At least - I was close :) Thanks! -afan Klaus Reimer wrote: Afan Pasalic wrote: But, I can't figure out how to split them back? $string_back = explode('\n', $string); That one is the right one. But you must use double quotes, not single quotes. Escaped characters (except \') i

Re: [PHP] splitting string

2004-11-16 Thread Klaus Reimer
Afan Pasalic wrote: But, I can't figure out how to split them back? $string_back = explode('\n', $string); That one is the right one. But you must use double quotes, not single quotes. Escaped characters (except \') in single quoted strings are not processed. -- PHP General Mailing List (http://

Re: [PHP] splitting string

2004-11-16 Thread M. Sokolewicz
Afan Pasalic wrote: Chris W. Parker wrote: Yes. $string = "$string1|$string2|$string3|$string4|$string5"; $string_back = explode("|", $string); Ok, I'm going to change the code and use pipes :) Thanks to all of you.! -afan please explain... WHY is that better? -- PHP General Mailing List (http://

Re: [PHP] splitting string

2004-11-16 Thread Dennis Lahay
I usually put a bar "|" between each string, if I need to. $string = $string1."|".$string2."|".$string3."|".$string4."|".$string5; D On Nov 16, 2004, at 12:01 PM, Afan Pasalic wrote: I create a string from other strings: $string = $string1."\n".$string2."\n".$string3."\n".$string4."\n".$string5;

Re: [PHP] splitting string

2004-11-16 Thread Jason Wong
On Wednesday 17 November 2004 02:01, Afan Pasalic wrote: > I create a string from other strings: > $string = $string1."\n".$string2."\n".$string3."\n".$string4."\n".$string5; > and then store it in DB. > > But, I can't figure out how to split them back? > > Tried: > $string_back = explode('\n', $

Re: [PHP] splitting string

2004-11-16 Thread Greg Donald
On Tue, 16 Nov 2004 12:01:04 -0600, Afan Pasalic <[EMAIL PROTECTED]> wrote: > I create a string from other strings: > $string = $string1."\n".$string2."\n".$string3."\n".$string4."\n".$string5; > and then store it in DB. > > But, I can't figure out how to split them back? > > Tried: > $string_ba

Re: [PHP] splitting string into array

2004-09-29 Thread blackwater dev
Thanks all! On Wed, 29 Sep 2004 14:55:58 +0100, Chris Dowell <[EMAIL PROTECTED]> wrote: > In PHP4 > > $array = explode(';', chunk_split("A12B05C45D34", 3, ';')); > > In PHP4 > > $array = str_split("A12B05C45D34", 3); > > RTFM > > Cheers > > Chris > > > > blackwater dev wrote: > > > How

Re: [PHP] splitting string into array

2004-09-29 Thread Matt M.
> Example, > A12B05C45D34 > > I need to split this into chunks of three A12,B05,C45..etc? not sure if your string will always be the same patter but this might work $string = 'A12B05C45D34'; $array = preg_split ( '/([a-zA-Z]\d{2})/', $string, -1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );

Re: [PHP] splitting string into array

2004-09-29 Thread Gareth Williams
Try something like this: $string = 'A12B05C45D34'; $string = chunk_split($string, 3, ':'); //Should give you 'A12:B05:C45:D34'; $array = explode(":",$string); Cheers, Gareth On 29 Sep 2004, at 15:40, blackwater dev wrote: How can I take a string and create an array? Example, A12B05C45D34 I need to

Re: [PHP] splitting string into array

2004-09-29 Thread Martin Holm
blackwater dev wrote: How can I take a string and create an array? Example, A12B05C45D34 I need to split this into chunks of three A12,B05,C45..etc? Thanks! | use str_split() if you dont have php5, you can use the following code: | if (!function_exists('str_split')) { function str_split ($s

Re: [PHP] splitting string into array

2004-09-29 Thread Marek Kilimajer
blackwater dev wrote: How can I take a string and create an array? Example, A12B05C45D34 I need to split this into chunks of three A12,B05,C45..etc? Thanks! $chunks = preg_split('/(.{3})/', $str, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); -- PHP General Mailing List (http://www.php.net/

Re: [PHP] splitting string into array

2004-09-29 Thread Chris Dowell
In PHP4 $array = explode(';', chunk_split("A12B05C45D34", 3, ';')); In PHP4 $array = str_split("A12B05C45D34", 3); RTFM Cheers Chris blackwater dev wrote: How can I take a string and create an array? Example, A12B05C45D34 I need to split this into chunks of three A12,B05,C45..etc? Thanks! -- PHP Ge

Re: [PHP] splitting string into array

2004-09-29 Thread raditha dissanayake
blackwater dev wrote: How can I take a string and create an array? Example, A12B05C45D34 I need to split this into chunks of three A12,B05,C45..etc? split() chunk_split() substr() preg_split() Thanks! -- Raditha Dissanayake. ---