string to array

please help me with converting string to an array:

I have a number for example 3567 that I wish to convert to an array for
example $arr=(3,5,6,7)

I have seen in PHP manual that there is str_split function, but when I write
it in my Dreamweaver he does not recognize it like a function and it's not
working when I put on web. Is there some other function?

--
Anka Bajurin, art direktor
vizual media d.o.o.
Ivana Matetica Ronjgova 35
HR-10000 Zagreb
tel.: +385 1 3863 414
fax: +385 1 3887 775
gsm: +385 98 642 711
anka [at] vizualmedia.hr
info [at] vizualmedia.hr
www.vizualmedia.hr

Informacija sadržana u ovoj poruci elektronske pošte je namijenjena
naznacenim primateljima, a sadržaj iste može biti povjerljive prirode.
Ako ste ovu poruku primili greškom i nije vam namijenjena, odmah je
obrišite sa svog sistema i obavijestite pošiljatelja da ste to napravili.
Distribucija, kopiranje i otvaranje privitaka je strogo zabranjeno.

The information contained in this message is assigned only to intended
recipient and may contain legally privileged or confidential information.
If you received this message in error and you are not the intended
recipient,
delete it immediately from your system and notify sender by e-mail that you
have done so. Distribution, copying and open attachments is strictly
prohibited.
Ana [ Di, 19 Juni 2007 14:05 ] [ ID #1742056 ]

Re: string to array

I just noticed that I didn't delete my signature, please ignore it
Ana [ Di, 19 Juni 2007 14:21 ] [ ID #1742057 ]

Re: string to array

ana wrote:
> please help me with converting string to an array:
>
> I have a number for example 3567 that I wish to convert to an array for
> example $arr=(3,5,6,7)
>
> I have seen in PHP manual that there is str_split function, but when I write
> it in my Dreamweaver he does not recognize it like a function and it's not
> working when I put on web. Is there some other function?
>
function str_to_array($v)
{
return preg_split('//', $v, -1, PREG_SPLIT_NO_EMPTY);
}

$x = str_to_array(1234);

Result:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
Joe Scylla [ Di, 19 Juni 2007 15:12 ] [ ID #1742058 ]

Re: string to array

..oO(ana)

>please help me with converting string to an array:
>
>I have a number for example 3567 that I wish to convert to an array for
>example $arr=(3,5,6,7)
>
>I have seen in PHP manual that there is str_split function, but when I write
>it in my Dreamweaver he does not recognize it like a function and it's not
>working when I put on web.

str_split requires PHP 5. You should upgrade if possible.

>Is there some other function?

You could try split() or preg_split() for example.

Micha
Michael Fesser [ Di, 19 Juni 2007 15:16 ] [ ID #1742059 ]

Re: string to array

it helped a lot,
thank you

"Joe Scylla" <joe.scylla [at] gmail.com> wrote in message
news:f58kkv$lpn$01$1 [at] news.t-online.com...
> ana wrote:
>> please help me with converting string to an array:
>>
>> I have a number for example 3567 that I wish to convert to an array for
>> example $arr=(3,5,6,7)
>>
>> I have seen in PHP manual that there is str_split function, but when I
>> write it in my Dreamweaver he does not recognize it like a function and
>> it's not working when I put on web. Is there some other function?
>>
> function str_to_array($v)
> {
> return preg_split('//', $v, -1, PREG_SPLIT_NO_EMPTY);
> }
>
> $x = str_to_array(1234);
>
> Result:
> Array
> (
> [0] => 1
> [1] => 2
> [2] => 3
> [3] => 4
> )
Ana [ Di, 19 Juni 2007 15:35 ] [ ID #1742061 ]

Re: string to array

On Jun 19, 9:12 am, Joe Scylla <joe.scy... [at] gmail.com> wrote:
> ana wrote:
> > please help me with converting string to an array:
>
> > I have a number for example 3567 that I wish to convert to an array for
> > example $arr=(3,5,6,7)
>
> > I have seen in PHP manual that there is str_split function, but when I write
> > it in my Dreamweaver he does not recognize it like a function and it's not
> > working when I put on web. Is there some other function?
>
> function str_to_array($v)
> {
> return preg_split('//', $v, -1, PREG_SPLIT_NO_EMPTY);
> }
>
> $x = str_to_array(1234);
>
> Result:
> Array
> (
> [0] => 1
> [1] => 2
> [2] => 3
> [3] => 4
> )

It's worth noting that you can also address individual characters in a
string like an array:

$str = '3567';
echo $str{2};

will output '6'.

If you really needed it to be an array then you could do something
like this:

function str_to_array($str) {
$a = array();
$len = strlen($str);

for($i = 0; $i < $len; $i++)
$a[$i] = $str{$i};

return $a;
}
zeldorblat [ Di, 19 Juni 2007 17:58 ] [ ID #1742062 ]

Re: string to array

..oO(ZeldorBlat)

>It's worth noting that you can also address individual characters in a
>string like an array:
>
>$str = '3567';
>echo $str{2};

echo $str[2];

The {} syntax will be deprecated in PHP 6.

Micha
Michael Fesser [ Di, 19 Juni 2007 18:05 ] [ ID #1742063 ]

Re: string to array

On Jun 19, 12:05 pm, Michael Fesser <neti... [at] gmx.de> wrote:
>
> The {} syntax will be deprecated in PHP 6.
>
> Micha

If it's ever finished :)
zeldorblat [ Di, 19 Juni 2007 18:32 ] [ ID #1742064 ]

Re: string to array

Post removed (X-No-Archive: yes)
Notifier Deamon [ Mi, 20 Juni 2007 19:42 ] [ ID #1744050 ]
PHP » alt.php » string to array

Vorheriges Thema: [Ann] HTML Purifier 2.0.0 released
Nächstes Thema: open_basedir: allowed path not recognized