splitting text and numbers
Posted 08 September 2006 - 05:00 PM
is there anyway i can split the text and the number, so that i have: MEM and 0001?
everytime i want to add a member i want 1 to be added so that it goes: mem0001, mem0002 etc
i know how to do the latter part, i just need to know how to split the mem from the number so that i can work out what the next one will be.
Posted 08 September 2006 - 06:17 PM
I know you said you know how to do this, but you do realize that the numbered portion is still going to be a string right? So you can't just say $numbers++ because you can't perform math on a string. I'm sure there's a way to convert data types....but I'm not sure off the top of my head.
Posted 09 September 2006 - 09:21 PM
Posted 09 September 2006 - 11:01 PM
Posted 09 September 2006 - 11:24 PM
<?php $str = "mem0001"; $mem = substr($str,0,3); $num = substr($str,3); echo $str . ' => ' . $mem . ',' . $num . '<br>'; $num++; echo '$num + 1 = ' . $num; echo '<br>New member number = ' . $mem . sprintf("%04d",$num); ?>
Posted 13 September 2006 - 04:48 PM
it is not adding the mem at the beginning, it is just numbers.
worked fine when i tried it with the code you have but when i used it in my function it dint work
any ideas why it is doing this?
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users