Re: Separating spaces from the rest
| From: | Justin Patrin | Date: | Fri, 30 Apr 2004 23:39:04 +0000 |
| Subject: | Re: Separating spaces from the rest | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185083@lists.php.net to get a copy of this message | ||
Anguz wrote:
Thanks! I was just reading that function in the manual when I got your reply. I tested it but I still have a couple of problems with it. print_r(preg_split('(\s+)', " word1 word2 word3.", -1, PREG_SPLIT_DELIM_CAPTURE)); I get this: Array (...I wonder why you're doing this, but here's an answer for you. BTW, if you use var_dump or var_export, you can see the whitespace :-). $arr = preg_split('/(^\s+)/', " word1 word2 word3.", -1,[0] => [1] => word1 [2] => word2 [3] => word3.) In [0] the spaces aren't there and it's splitting the other spaces too, where I need to only split the leading spaces. How should I write it? TIA, Anguz Kemper, Helmut wrote: Hi, See preg_explite and use "/(\s+)/" for explode string into array. Tanks, Kemper ------------------------------------------------------------------------ ----------------------------------------------------------------- Helmut Kemper kemper@kemper.com.br Celular (Mobile): 55 81 99268744 On 30/04/2004, at 20:22, Anguz wrote:I have an array with many strings, of which most have spaces or tabs at the beginning, but no fixed number of them. Example:$arr[0] = ' Hello.';How can I separate them into two strings? Like: Array ([0] => Array ( [0] => " " //I added the quotes to notice the space. [1] => Hello. )) TIA! Anguz -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
PREG_SPLIT_DELIM_CAPTURE);The ^ means beginning of string. This will still give you an empty string in $arr[0], so do something like: unset($arr[0]); $arr = array_values($arr); Or just write your code to expect the extra entry. ;-) -- paperCrane <Justin Patrin>