PHP匹配特定的字符串

问题描述 投票:0回答:1

AWS-HMAC-SHA256 Credential = eyJhbGciOiJIUzI1NiIsIngtc3MiOjEy / 20160911 / cn / user-service / request,SignedHeaders = host; x-aws-date,Signature = d9ee2d43f2067e4b8857f15fa8fff27820051d95a4ec31e93be866f201e0797a

如何定期匹配Credential,SignedHeaders,Signature?

preg-match-all
1个回答
0
投票

您可以使用explodearray_map而不是使用正则表达式:

$str = "AWS-HMAC-SHA256 Credential=eyJhbGciOiJIUzI1NiIsIngtc3MiOjEy/20160911/cn/user-service/request,SignedHeaders=host;x-aws-date, Signature=d9ee2d43f2067e4b8857f15fa8fff27820051d95a4ec31e93be866f201e0797a";
$res = array_map(function($x){
    return explode('=', $x)[1];
}, explode(',', $str));
print_r($res);

结果:

Array
(
    [0] => eyJhbGciOiJIUzI1NiIsIngtc3MiOjEy/20160911/cn/user-service/request
    [1] => host;x-aws-date
    [2] => d9ee2d43f2067e4b8857f15fa8fff27820051d95a4ec31e93be866f201e0797a
)

Demo


推荐问答