Assuming var1 and var2 only ever use the last four numbers (untested): $length = strlen($number); // get string length $var1 = substr($number,0,$length-4); // get number until only 4 numbers are left $var2 = substr($number,$length-4,2); // get 3rd and 4th last numbers. $var3 = substr($number,$length-2,2); // get last two numbers. Aaron On 11/14/06, Børge Holen <borge@xxxxxxxxxxx> wrote:
This numer has dynamic lenght, witch is the root of my problems. $number = 123456789 should print as following: var1: 12345 (and it is this lengt witch varies) var2: 67 var3: 89. I've been using substr with negative numbers to fetch the last two vars. thereafter explode to get the first number. Ok I understand the code and can use it, but it feels wrong. Does anyone have any idea on suitable functions for such a task, both more size (as in code) and speed effective. It is not a mission critical, but moreover a opinion of what things should look like. I've been looking into string/explode functions on php.net without getting past my current code. -- --- Børge Kennel Arivene http://www.arivene.net --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- +-------------------------------------------- | Aaron Koning | Information Technologist | Prince George, BC, Canada. +-------------------------------------------- | http://datashare.gis.unbc.ca/fist/ | http://datashare.gis.unbc.ca/gctp-js/ +--------------------------------------------