如何在PHP中打印对象中的字符串

时间:2014-06-25 03:37:03

标签: php date object

我得到以下对象以响应PHP中的调用:

  

交易[id = g855fm,类型=销售,金额= 100.00,        status = processed,createdAt = Tuesday,24-Jun-14 19:17:58        UTC]

我可以回复idamountstatus等,但createdAt不会打印。也许是因为它中有一个逗号(,)?我想将状态从字符串格式转换为mm / dd / yyyy,但我无法将其格式化为mm / dd / yyyy,因为我无法获得createdAt。

echo $object->createdAt;不打印任何内容。

echo $object->id;打印g855fm

echo $object->status;打印processed

这是整个对象:

Braintree_Subscription[
    addOns=,
    balance=0.00,
    billingDayOfMonth=24,
    billingPeriodEndDate=Wednesday, 23-Jul-14 00:00:00 MDT,
    billingPeriodStartDate=Tuesday, 24-Jun-14 00:00:00 MDT,
    currentBillingCycle=1,
    daysPastDue=,
    discounts=,
    failureCount=0,
    firstBillingDate=Tuesday, 24-Jun-14 00:00:00 MDT,
    id=6q6qg2,
    merchantAccountId=XXXX,
    neverExpires=1,
    nextBillAmount=100.00,
    nextBillingPeriodAmount=100.00,
    nextBillingDate=Thursday, 24-Jul-14 00:00:00 MDT,
    numberOfBillingCycles=,
    paidThroughDate=Wednesday, 23-Jul-14 00:00:00 MDT,
    paymentMethodToken=3mzhf6,
    planId=XXXX,
    price=100.00,
    status=Active,
    trialDuration=,
    trialDurationUnit=day,
    trialPeriod=,
    descriptor=Braintree_Descriptor[
        name=, phone=
        ],
    transactions=
    0=Braintree_Transaction[
        id=h2v7qm,
        type=sale,
        amount=100.00,
        status=submitted_for_settlement,
        createdAt=Wednesday, 25-Jun-14 03:53:07 UTC,
        creditCardDetails=Braintree_Transaction_CreditCardDetails[
            token=3mzhf6,
            bin=411111,
            last4=1111,
            cardType=Visa,
            expirationMonth=06,
            expirationYear=2014,
            customerLocation=US,
            cardholderName=,
            imageUrl=https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox&merchant_id=XXXX,
            prepaid=Unknown,
            healthcare=Unknown,
            debit=Unknown,
            durbinRegulated=Unknown,
            commercial=Unknown,
            payroll=Unknown,
            issuingBank=Unknown,
            countryOfIssuance=Unknown,
            productId=Unknown,
            venmoSdk=,
            expirationDate=06/2014,
            maskedNumber=411111******1111
        ],
        customerDetails=Braintree_Transaction_CustomerDetails[
            id=59273593,
            firstName=XXXX,
            lastName=,
            company=,
            email=XXXX,
            website=,
            phone=XXXX,
            fax=
        ]
    ]
]

我正在访问它:$object->transactions[0]->createdAt

更新

echo $object->transactions[0]->createdAt->format('r');是:星期三,2014年6月25日04:07:42 +0000

我现在将尝试使用它来进行日期格式化。我希望它以date(dd/mm/yyyy)格式。知道怎么做吗?

2 个答案:

答案 0 :(得分:2)

我认为您已关闭显示错误。尝试回显DateTime对象时,您收到无提示致命错误。

尝试echo $object->transactions[0]->createdAt->format('d/m/Y');

答案 1 :(得分:1)

你应该打印像这样的对象

<?php print_r($object); ?>