php - Substring right after another substring -


so have big string, includes in middle following:

"(...) status: ativo identificador: f36ce5 meio de pagamento: cartão de crédito data de contratação: 25/03/2015 data de expiração: 25/03/2017 (...)" 

* "(...)" identify there more content before , after part

my goal isolate part right after "identificador:", i.e., need grab value "f36ce5" (which different every time, of course) , set variable.

i tried following code:

$initialstring = "status: ativo identificador: f37ce5 meio de pagamento: cartão de crédito data de contratação: 25/03/2015 data de expiração: 25/03/2017";   $arr = explode(":", $initialstring); $important = $arr[2]; echo $important; 

but getting

f37ce5 meio de pagamento 

what should f37ce5?

is there way tell php: "give string right after 'identificador:', , nothing more" ?

use regular expression. like:

<?php $pattern = '/identificador: (\w+)/'; preg_match($pattern, $initialstring, $matches); print_r($matches[1]); ?> 

$matches[1] contain string looking for.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -