Curt Zirzow wrote:
You forgot the pattern deliminator:
print_r(preg_split('/(\s+)/', " word1 word2 word3.", -1, PREG_SPLIT_DELIM_CAPTURE));


Curt

You're right, that fixed the space capturing.


Justin Patrin wrote:
> ...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,
> 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. ;-)


The ^ did the trick, thanks! I noticed the empty [0].

I'm doing this to display code in an indented way and to keep the indent if the line wraps, instead of going back all the way to the left. So I'm putting the spaces in a <td> and the code line in another <td>, with a table for each line. I tested it and looks very well, now I'm writting the code to generate it.

Thank you all for your help! :)

Anguz

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to