Selectiong characters from an integer
Moderator: General Moderators
-
AshrakTheWhite
- Forum Commoner
- Posts: 69
- Joined: Thu Feb 02, 2006 6:47 am
Selectiong characters from an integer
Hello
Heres the problem i have, id like to take a certain ammount of characters from a string and print em out seperately.
for instance if i have a number like 129019289739749357 then if i wanted it to select the 4 first numbers out of that entire thing it would print out 1290
is there any way of doing that?
Heres the problem i have, id like to take a certain ammount of characters from a string and print em out seperately.
for instance if i have a number like 129019289739749357 then if i wanted it to select the 4 first numbers out of that entire thing it would print out 1290
is there any way of doing that?
Code: Select all
$numbers = "129019289739749357";
echo substr($numbers, 0, 4);i was thinking where goes the other numbers ???
because i use this function sometimes, i saw this post and ask myself and if i want to use the rest of the numbers...
i do some testes and substr() doesn't put the numbers in arrays..
you get:
string(1) "9"
the only way to use the other numbers is to do again a calculation with the substr($numbers, 0, 8 ); ??? or there is ther function that divides and put in arrays ???
and use like $get_number[0] and then you use for the other numbers $get_number[1]
because i use this function sometimes, i saw this post and ask myself and if i want to use the rest of the numbers...
i do some testes and substr() doesn't put the numbers in arrays..
Code: Select all
$numbers = 123456789;
$get_number = substr($numbers, -1, 1 );
var_dump($get_number);string(1) "9"
the only way to use the other numbers is to do again a calculation with the substr($numbers, 0, 8 ); ??? or there is ther function that divides and put in arrays ???
and use like $get_number[0] and then you use for the other numbers $get_number[1]
Code: Select all
<?php
$str = '123';
echo $str[2]; //3
?>hmm
Code
Output:
Code
Code: Select all
$str = 12345678910;
$str_array = str_split($str,4);
print_r($str_array);Code: Select all
Array (
[0] => 1234
[1] => 5678
[2] => 910
)Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
str_split() is php 5 only, without using the compatibility layer from pear.
nahh what im saying is after you dojshpro2 wrote:Code: Select all
<?php $str = '123'; echo $str[2]; //3 ?>
Code: Select all
$some = substr($str, 0, 1); // for exampleplease see this post...duk wrote:i was thinking where goes the other numbers ???
because i use this function sometimes, i saw this post and ask myself and if i want to use the rest of the numbers...
i do some testes and substr() doesn't put the numbers in arrays..
you get:Code: Select all
$numbers = 123456789; $get_number = substr($numbers, -1, 1 ); var_dump($get_number);
string(1) "9"
the only way to use the other numbers is to do again a calculation with the substr($numbers, 0, 8 ); ??? or there is ther function that divides and put in arrays ???
and use like $get_number[0] and then you use for the other numbers $get_number[1]