PHP匹配特定的字符串

时间:2018-09-12 05:05:59

标签: preg-match-all

  

AWS-HMAC-SHA256   凭证= eyJhbGciOiJIUzI1NiIsIngtc3MiOjEy / 20160911 / cn / user-service / request,SignedHeaders = host; x-awsdate,   签名= d9ee2d43f2067e4b8857f15fa8fff27820051d95a4ec31e93be866f201e0797a

常规如何匹配凭据,SignedHeaders,签名?

1 个答案:

答案 0 :(得分: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