Jump to content

PHP array (json_decode) Remove line breaks


reldridge

Recommended Posts

Trying to convert json to PHP array, and having issues with line breaks in the json output from Ecwid.

 

Ecwid Shopping Cart (API) - GET Orders
http://developers.ecwid.com/api-documentation#orders
 
PHP  using curl to get json data of new orders
<?php
# An HTTP GET request example

$url = 'https://app.ecwid.com/api/v3/{STOREID}/orders?paymentStatus=PAID&fulfillmentStatus=AWAITING_PROCESSING&token={TOKEN}';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);

$json_obj = preg_replace('\n', '', utf8_encode($data));
$json_obj = json_decode($data, true);


foreach ($json_obj['items'] as $item) {
	echo "<pre>";
    print_r($item);
} 


?>

Array Output:  (please see [orderComments])

Array
(
    [vendorOrderNumber] => 0137062
    [subtotal] => 79
    [total] => 138.65
    [email] => annaschutt@hotmail.com
    [externalTransactionId] => 96U34224JE632150D
    [paymentModule] => PayPalStandard
    [paymentMethod] => PayPal / Credit Card
    [tax] => 0
    [ipAddress] => 80.217.64.221
    [couponDiscount] => 0
    [paymentStatus] => PAID
    [paymentMessage] => Your order has been approved
    [fulfillmentStatus] => AWAITING_PROCESSING
    [orderNumber] => 7062
    [refererUrl] => fbtab:https://www.facebook.com/fvhardmerchandise/?sk=app_251458316228
    [orderComments] => If its possible to get an autograph from the captain and the crew to my husband Amadeus it would be great. He just loves the show on tv and is also a fisherman here in Sweden.

Thank you
Anna
    [volumeDiscount] => 0
    [customerId] => 24198510
    [membershipBasedDiscount] => 0
    [totalAndMembershipBasedDiscount] => 0
    [discount] => 0
    [usdTotal] => 138.65
    [globalReferer] => https://staticxx.facebook.com/platform/page_proxy/r/hv09mZVdEP8.js
    [createDate] => 2016-01-08 14:00:20 +0000
    [updateDate] => 2016-01-08 14:04:15 +0000
    [createTimestamp] => 1452261620
    [updateTimestamp] => 1452261855
    [items] => Array
        (
            [0] => Array ............
Edited by reldridge
Link to comment
Share on other sites

What parse errors? Line breaks are totally allowed in XML.

<orderComments>If its possible to get an autograph from the captain and the crew to my husband Amadeus it would be great. He just loves the show on tv and is also a fisherman here in Sweden.

Thank you
Anna</orderComments>
If you called nl2br on the comment and then put it into XML, that would not work because

would be interpreted as an XML node when you didn't want it to be.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.