Separate hex blocks in PHP -


anyone knows way "separate" blocks of hex code?

[49cd0d18] -> 1238175000 [00010000] -> 1 [0069] -> 105 [543ace68] -> timestamp 000000000000000000000000000000000000000  complete: 49cd0d1800010000543ace68000000000000000000000000000000000000000 

oh, of course... values, can different... know, not same. so, need know how "count" blocks, , then, "cut".

i'll grateful help!

regex easy solution problem theses:

you can see regex on link: https://regex101.com/r/qp1bc7/1

note: don't forget put delimiter (the slashes in example) around regex when use in code :

/^(\w{8})(\w{8})(\w{4})(\w{8})(\w{39})$/ 
  1. the caret , dollar sign delimit respectively beginning , ending of string.
  2. the parenthesis capturing groups.
  3. \w match letter (a-z in lower , upper case), digits (0-9) , underscore (_).
  4. {8} means must match 8 characters

and can see example of code here:

http://sandbox.onlinephpfunctions.com/code/c3a0ec3a45c53eb2c1b8e21cb978253ea4a28e52

the third parameter array store match of regex (it passed reference, have create before using it). first (0) index whole match , successive index (1-6) result of capturing groups (there 5 of them).

you extract substring php native functions.

$string = "49cd0d18000100000069543ace68000000000000000000000000000000000000000";  $matches = array();  $matches[] = substr($string, 0, 8);  $matches[] = substr($string, 8, 8);  $matches[] = substr($string, 16, 4);  $matches[] = substr($string, 20, 8);  $matches[] = substr($string, 28, 39);  var_dump($matches); 

you can test code here: http://sandbox.onlinephpfunctions.com/code/18935d55feb86dffdc17f8854572e0935b4aab0e

additional note: php native functions faster regex. regular expressions have compile every time use them (but php keep pool of last 1000 regexes used). can benchmark both solutions if performance important matter. otherwise, i'd both solutions pretty equivalent.

good success , don't forget like,

jonathan parent-lévesque montreal


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -