# extracting just a piece out of a 13digit number

5 replies to this topic

### #1 GremlinP1R

GremlinP1R
• Members
• 62 posts
• LocationSouth Africa

Posted 10 October 2006 - 03:30 PM

Hai there. I'm trying to get just 2digits out a 13digit number.
The number looks as follow 1234567890123 now I only whant it to show nuber 56.
How can I do this? Can any one pls help me!

What I tryed were
\$num = \$row['num'];
\$nu = ereg_replace("problem","",\$num);

Okay I'm sure there's a beter  way of doing it, But thats how far my brain can think.

### #2 trq

trq
• Staff Alumni
• 31,041 posts

Posted 10 October 2006 - 03:32 PM

```\$nu = \$num{5}.\$num{6};
```

### #3 GremlinP1R

GremlinP1R
• Members
• 62 posts
• LocationSouth Africa

Posted 10 October 2006 - 03:34 PM

Okay hehe my mistake!

The 13digit numer always change! But just need position 5 and 6's numbers

### #4 trq

trq
• Staff Alumni
• 31,041 posts

Posted 10 October 2006 - 03:39 PM

My code will allways return positions 5 and 6.

### #5 GremlinP1R

GremlinP1R
• Members
• 62 posts
• LocationSouth Africa

Posted 10 October 2006 - 03:55 PM

Thanx Thorpe, just had to change the 5 to 4 and 6 to 5 to get position 5 and 6.
But working now.

### #6 kenrbnsn

kenrbnsn
• Staff Alumni
• 8,235 posts
• LocationHillsborough, NJ, USA

Posted 10 October 2006 - 04:01 PM

Actually your code returns position 4 & 5, since position 0 (zero) is the first position.

Another way of doing it would be:
```<?php
\$num = '1234567890123';
\$num56 = substr(\$num,5,2);
echo \$num56;
?>```

Ken

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users