jquery用逗号分隔列表输出

时间:2014-11-14 05:29:53

标签: jquery csv

我无法将其输出到以逗号分隔的列表中。输出只是444064451244515.我需要它是44406,44512,44515

<?php
// return zip codes within a given radius of a given zip code
// TO DO - validate POST values

if(isset($_POST['findzip'])) {
    $myzip = $_POST['myzip'];
    $radius = $_POST['radius'];
    $api_key = $modx->getOption('zipcode_api');

    $url = "https://zipcodedistanceapi.redline13.com/rest/$api_key/radius.json/$myzip/$radius/mile";

    // cURL stuff
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    $response = curl_exec($ch);

    $response = utf8_encode($response);

    $zips = $modx->fromJson($response);

        foreach ($zips['zip_codes'] as $zip) {
        $output .= $zip['zip_code'].split(",");
    }

    return $output;
}

return;

1 个答案:

答案 0 :(得分:0)

正如上面的评论所述,这样的事情应该有效:

<?php

 if(isset($_POST['findzip'])) {
    $myzip = $_POST['myzip'];
    $radius = $_POST['radius'];
    $api_key = $modx->getOption('zipcode_api');

    $url = "https://zipcodedistanceapi.redline13.com/rest/$api_key/radius.json/$myzip/$radius/mile";

    // cURL stuff
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    $response = curl_exec($ch);

    $response = utf8_encode($response);

    $zips = $modx->fromJson($response);

    return implode(',', $zips);
}