Php 在浏览器中显示部分输出
背景: 我正在呼叫soapurl&根据ShipmentNumber在浏览器中获取消息 案例1:当我在浏览器中运行代码时,对于一些ShipmentNumber,我得到以下结果作为输出:Php 在浏览器中显示部分输出,php,Php,背景: 我正在呼叫soapurl&根据ShipmentNumber在浏览器中获取消息 案例1:当我在浏览器中运行代码时,对于一些ShipmentNumber,我得到以下结果作为输出: stdClass Object ( [Transaction] => stdClass Object ( [Reference1] => 10000128254545 [Reference2] =>
stdClass Object
(
[Transaction] => stdClass Object
(
[Reference1] => 10000128254545
[Reference2] =>
[Reference3] =>
[Reference4] =>
[Reference5] =>
)
[Notifications] => stdClass Object
(
)
[HasErrors] => 1
[ProcessedShipmentHolds] => stdClass Object
(
[ProcessedShipmentHold] => stdClass Object
(
[ID] => 42863418581
[HasErrors] => 1
[Notifications] => stdClass Object
(
[Notification] => stdClass Object
(
[Code] => ERR65
[Message] => Hold of the same type already exists
)
)
)
)
)
案例2:对于其他一些ShipmentNumber,我得到以下结果:
stdClass Object
(
[Transaction] => stdClass Object
(
[Reference1] => 10000128254545
[Reference2] =>
[Reference3] =>
[Reference4] =>
[Reference5] =>
)
[Notifications] => stdClass Object
(
)
[HasErrors] =>
[ProcessedShipmentHolds] => stdClass Object
(
[ProcessedShipmentHold] => stdClass Object
(
[ID] => 42863421156
[HasErrors] =>
[Notifications] => stdClass Object
(
)
)
)
)
要求:
但我只想在浏览器中显示[Message]值。意味着,在案例1中,我希望显示“相同类型的保留已存在””,在案例2中,我希望在浏览器中显示“无消息”
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$soapClient = new SoapClient('https://ws.aramex.net/ShippingAPI.V2/Shipping/Service_1_0.svc?wsdl');
$params = array(
'ClientInfo' => array('AccountNumber' => 'IN',
'Version' => 'v1.0'
),
'Transaction' => array(
'Reference1' => '',
'Reference5' => ''
),
'ShipmentHolds'=> array(
'ShipmentHoldDetails' => array(
'ShipmentNumber' =>'42863421156',
'Comment' =>'test Order'
)
)
);
try {
$auth_call = $soapClient->HoldShipments($params);
echo '<pre>';
print_r($auth_call);
die();
} catch (SoapFault $fault) {
die('Error : ' . $fault->faultstring);
}
?>
试试这段代码。您需要访问正确的字段才能显示消息 您的邮件位于:
if(isset($auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message)){
echo $auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message;
}
else{
echo "No Message";
}
但是根据你的第二个问题,有时候你没有,所以你可以选择以下方式:
isset($auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message)?$Message=$auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message:$Message='No Message';
echo $Message;
您可以使它更“优雅”,并使用三元运算符,如
请去读。您需要向我们解释您在实现“需求”时遇到的实际问题。请让我知道否决的原因,以便我更正它….@CBroe感谢您的评论,我需要显示输出的
部分
,而不是完整输出
…这仍然只是您的需求,但这并不能解释你在这方面遇到了什么问题。这不是一个你提出要求的地方,有人会帮你做的。@C抱歉,我会尽快更新问题。……谢谢,现在对于每个装运编号
,它会显示无消息
。。。。。。但对于某些装运编号
,应显示已存在的相同类型的保留
通常,代码检查字段消息是否存在,如果存在,则显示其值(文本),否则不显示消息。如果我回答了您的问题,请将其标记为已接受。一旦成功,我当然会接受您的回答,但如果我使用相同的装运编号
&如果我在qiestion中使用代码,则其显示为相同类型的保持已存在
,但如果我将您的代码用于相同的装运编号
,而不是显示为无消息
,请检查这一点….我使用的路径是错误的,因为我从您以前的图像中获取的路径不同。更正了我的答案。请现在试一试
isset($auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message)?$Message=$auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message:$Message='No Message';
echo $Message;