Click to See Complete Forum and Search --> : Is there a way to split a string into 2 parts?


bsmbahamas
01-21-2008, 11:23 AM
i have an 8 digit string...

$id = 12345678

what i want to do is split it in two so that
i have 4 digits in each part.

$arr = str_split($id,4);

seems to be a solution, but i think
my host is using php 4 and that functions
appears to only work in php 5.

any other way? or maybe i'm using it wrong.

i copied and pasted sample code from php.net and
another site, but none worked. so i'm assuming it
because my host is using php 4.

how do i tell the php versiona gain?
php_info() or something liek that right?

abou.hmed
01-21-2008, 11:31 AM
try to do it by this way
$id1=substr ($id, 0,-4);
$id2=substr ($id, 4);
it should work i guess

bsmbahamas
01-21-2008, 11:33 AM
try to do it by this way
$id1=substr ($id, 0,-4);
$id2=substr ($id, 4);
it should work i guess

thanks while i was waiting for a response,
i tried this, which works fine:

$id = 12345678;
$part1 = substr($id, 0, 4);
$part2 = substr($id, 4, 4);