如何从表情中获取错误消息?

我正在使用PHP代码,并希望获取以下句子中的错误消息:

$str='Data Error (400): {"error_messages":["Currency is not included in the list (IDR,SGD)"]} | Request url: https://app.sandbox.xxx.com/snap/v1/transactions'

$str='Data Error (411): {"error_messages":["access denied,please check client key or server key"]} | Request url: https://app.sandbox.xxx.com/snap/v1/transactions';

$str='Data Error (400): {"error_messages":["Order ID Already Paid and Utilized"]} | Request url: https://app.sandbox.xxx.com/snap/v1/transactions';

$str='Data Error (401): {"error_messages":["Invalid Transaction Type"]} | Request url: https://app.sandbox.xxx.com/snap/v1/transactions';

在上面的示例中,我想显示以下消息输出:

Currency is not included in the list (IDR,SGD)

access denied,please check client key or server key

Order ID Already Paid and Utilized

Invalid Transaction Type

我正在尝试使用以下正则表达式代码:

preg_match('/{(.*?)}/',$str,$matches);
echo "<pre>";
print_r($matches[0]);

但是我得到的响应是:{"error_messages":["Currency is not included in the list (IDR,SGD)"]}而不是Currency is not included in the list (IDR,SGD)

请帮助我如何仅获取错误消息文本?

cyc51314210 回答:如何从表情中获取错误消息?

您可以尝试使用此正则表达式

preg_match('/\[\"(.*?)\"\]/',$str,$matches);
echo "<pre>";
print_r($matches[0]);
本文链接:https://www.f2er.com/3138833.html

大家都在问