PHP takes data from the array SEPARATE

1

I get the value so \/Date(770094000000-0300)\/ but I need to just recover the value 770094000000 to be able to convert to date.

    
asked by anonymous 23.09.2014 / 23:45

3 answers

4

You can use an ER, see an example on ideone .

$string = '/Date(770094000000-0300)/';
preg_match( "/([0-9]+)-([0-9]+)/" , $string , $match );
print_r( $match );

// output
array
(
    [0] => 770094000000-0300
    [1] => 770094000000
    [2] => 0300
)
    
24.09.2014 / 00:11
4

Simple solution for fixed numbering (the number will always be the same size).

$minha_string = '/Date(770094000000-0300)/';

$numero_desejado = substr($minha_string, 6, 12);

echo $numero_desejado; // irá exibir 770094000000

Solution using Regular Expressions.

$minha_string = '/Date(770094000000-0300)/';

preg_match('/\((\d+)/', $minha_string, $numero_desejado );

echo $numero_desejado[1]; // irá exibir 770094000000
    
24.09.2014 / 00:13
2

You can use the preg_match function and get the values using a regular expression:

Demo Ideone

$str = '/Date(770094000000-0300)/';
preg_match( '/\d+\-\d+/', $str, $match );
var_dump( $match );
    
24.09.2014 / 00:11