PHP variable splitting

This is a discussion on PHP variable splitting within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Is there a command in PHP that will allow me to split a text variable into an array by length ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-27-2004
Papago
 
Posts: n/a
Default PHP variable splitting

Is there a command in PHP that will allow me to split a text variable into
an array by length rather than using a delimiter? What I want to do is have
it separate into an array entity for every 2 characters. So if you put in
the word "european" you would get:

$array[0] = "eu"
$array[1] = "ro"
$array[2] = "pe"
$array[3] = "an"

Is there a PHP command that will do this for me in one step?


Reply With Quote
  #2 (permalink)  
Old 08-27-2004
Andy Hassall
 
Posts: n/a
Default Re: PHP variable splitting

On Fri, 27 Aug 2004 16:53:23 -0400, "Papago" <me@myplace.com> wrote:

>Is there a command in PHP that will allow me to split a text variable into
>an array by length rather than using a delimiter? What I want to do is have
>it separate into an array entity for every 2 characters. So if you put in
>the word "european" you would get:
>
>$array[0] = "eu"
>$array[1] = "ro"
>$array[2] = "pe"
>$array[3] = "an"
>
>Is there a PHP command that will do this for me in one step?


http://uk.php.net/manual/en/function.str-split.php

Otherwise a simple loop with substr would do it.
Or preg_split.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:38 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0