use of str_split

use of str_split

am 09.08.2007 13:53:53 von Asim

--0-1494350565-1186660433=:79947
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Hi

when i try to use this function


str_split()

it shows me as invalid function


what is solution

i want to split certain length of string into an array


bye





Asim Jamil - 0092 345 4025907, Pakistan

---------------------------------
Luggage? GPS? Comic books?
Check out fitting gifts for grads at Yahoo! Search.
--0-1494350565-1186660433=:79947--

Re: use of str_split

am 09.08.2007 14:12:53 von Brad Bonkoski

Looks like the function str_split() is a PHP 5 addition, so I guess it
might be because you are using php 4?

You can also do this with substr() function...
Something like this:
$str = "abcdefg";
$arr = Array();
for($i=0; $i< strlen($str); $i++) {
$arr[] = substr($str, $i, 1);
}
print_r($arr);
?>

HTH
-B

Asim wrote:
> Hi
>
> when i try to use this function
>
>
> str_split()
>
> it shows me as invalid function
>
>
> what is solution
>
> i want to split certain length of string into an array
>
>
> bye
>
>
>
>
>
> Asim Jamil - 0092 345 4025907, Pakistan
>
> ---------------------------------
> Luggage? GPS? Comic books?
> Check out fitting gifts for grads at Yahoo! Search.
>

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

Re: use of str_split

am 09.08.2007 14:19:20 von Stut

Asim wrote:
> Hi
>
> when i try to use this function
>
>
> str_split()
>
> it shows me as invalid function

Are you using PHP 5? That function does not exist in PHP 4.

> what is solution
>
> i want to split certain length of string into an array

// NB: UNTESTED

$string = 'This is a string';
$certainlength = 5;
$pos = 0;
$stringlen = strlen($string);
$array = array();
while ($pos < $stringlen)
{
$array[] = substr($string, $pos, $certainlength);
$pos += $certainlength;
}

// $array now contains an element for every $certainlength characters
// in $string

-Stut

--
http://stut.net/

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

RE: use of str_split

am 09.08.2007 16:22:53 von Bastien Koert

--_67fe3460-8777-405c-bebd-16c57a540bd9_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


explode(delimiter, $string);
=20
is the correct function
=20
=20
=20
Bastien> Date: Thu, 9 Aug 2007 04:53:53 -0700> From: j.asim@yahoo.com> To: =
php-db@lists.php.net> Subject: [PHP-DB] use of str_split> > Hi> > when i tr=
y to use this function> > > str_split()> > it shows me as invalid function>=
> > what is solution> > i want to split certain length of string into an a=
rray> > > bye> > > > > > Asim Jamil - 0092 345 4025907, Pakistan> > -------=
--------------------------> Luggage? GPS? Comic books? > Check out fitting =
gifts for grads at Yahoo! Search.
____________________________________________________________ _____
Connect to the next generation of MSN Messenger=A0
http://imagine-msn.com/messenger/launch80/default.aspx?local e=3Den-us&sourc=
e=3Dwlmailtagline=

--_67fe3460-8777-405c-bebd-16c57a540bd9_--

Re: use of str_split

am 09.08.2007 16:30:33 von Brad Bonkoski

This was my initial thought too, but from the manual:

If /delimiter/ is an empty string (""), *explode()* will return *FALSE*.
If /delimiter/ contains a value that is not contained in /string/, then
*explode()* will return an array containing /string/.

So, this would not satisfy the functionality the OP alluded to.
-B


Bastien Koert wrote:
> explode(delimiter, $string);
>
> is the correct function
>
>
>
> Bastien> Date: Thu, 9 Aug 2007 04:53:53 -0700> From: j.asim@yahoo.com> To: php-db@lists.php.net> Subject: [PHP-DB] use of str_split> > Hi> > when i try to use this function> > > str_split()> > it shows me as invalid function> > > what is solution> > i want to split certain length of string into an array> > > bye> > > > > > Asim Jamil - 0092 345 4025907, Pakistan> > ---------------------------------> Luggage? GPS? Comic books? > Check out fitting gifts for grads at Yahoo! Search.
> ____________________________________________________________ _____
> Connect to the next generation of MSN Messenger
> http://imagine-msn.com/messenger/launch80/default.aspx?local e=en-us&source=wlmailtagline
>

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