PHP takes data from the SPLIT array

Asked

Viewed 381 times

1

I get value like this \/Date(770094000000-0300)\/ but I need to recover only the value 770094000000 for power converts to date.

  • The size of the numbers is always equal?

  • yes why he’s taking the date of birth .

  • then just use substr() to get only that part there. You tell where it starts and where it ends...

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
)

4

Simple solution to 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
  • That’s what I said up there.

  • @Zebradomal true, I really said :-)

2

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

Demo Ideone

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.