dongwen3410 2014-06-25 03:37
浏览 74
已采纳

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

I get the following object in response to a call in PHP:

Transaction[id=g855fm, type=sale, amount=100.00, status=processed, createdAt=Tuesday, 24-Jun-14 19:17:58 UTC]

I am able to echo id, amount, status etc. but createdAt does not print. Perhaps because it has a comma (,) in it? I want to convert the sate from string format to mm/dd/yyyy but I can not format it to mm/dd/yyyy because I am not able to get createdAt.

echo $object->createdAt; prints nothing.

echo $object->id; prints g855fm.

echo $object->status; prints processed.

This is the whole object:

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=
        ]
    ]
]

I am accessing it like: $object->transactions[0]->createdAt

Update:

echo $object->transactions[0]->createdAt->format('r'); is: Wed, 25 Jun 2014 04:07:42 +0000

I will now try to use it now for date formatting. I want it in date(dd/mm/yyyy) format. Any idea how to do that?

  • 写回答

2条回答 默认 最新

  • duandaodao6951 2014-06-25 04:20
    关注

    I think that you have turned off display errors. When trying to echo DateTime object you are receiving silent fatal error.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号