다른곳으로 JSON방식으로 전달해야한다는데요~~

다른곳으로 JSON방식으로 전달해야한다는데요~~

QA

다른곳으로 JSON방식으로 전달해야한다는데요~~

본문

고수님들의 도움으로 

<form ... /form> 양식으로 입력된 정보를 

curl으로 다른 곳으로 보내는것은 확인하였습니다. 

 

쩝 상대방이 json방식으로 데이타를 받는다는데~~

어떤것을 참고해봐야할까요???

부탁드립니다.

 

json 방식으로 

 

<?php

 

$name = $_POST['name'] ;

$phone = $_POST['phone'] ;

 

$result= array('resut'=>true, 'member'=>array('name'=>$name));

echo json_encode($result); exit;

?>

 

한글은 깨지네요

 {"resut":true,"member":{"name":"\ubc15\ub450\ub9ac","phone":"0130430"}}

 

 

 

curl 형태로 url 연동

==================================================================================


<?php
    $ch = curl_init();                    // Initiate cURL
    $url = "http://xxxxxxx.com/xxx/xxx"; // Where you want to post data
    $phone = $_POST['phone'];
    $name = $_POST['name'] ;
    $contents = $_POST['contents'] ;
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_POST, true);  // Tell cURL you want to post something
    curl_setopt($ch, CURLOPT_POSTFIELDS, "id=testd&pw=n1234&sendType=3&phone=$phone&name=$name&contents=$contents"); // Define what you want to post
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the output in string format
    $output = curl_exec ($ch); // Execute
    curl_close ($ch); // Close cURL handle
?>

 

 

이 질문에 댓글 쓰기 :

답변 1

※ 참고사항 : http://php.net/manual/kr/function.json-encode.php

 

php 5.4이상


$array = array("foo","bar");
$result = json_encode($array,JSON_UNESCAPED_UNICODE);

php 5.3이하


function my_json_encode($arr)
{
    //convmap since 0x80 char codes so it takes all multibyte codes (above ASCII 127). So such characters are being "hidden" from normal json_encoding
    array_walk_recursive($arr, function (&$item, $key) { if (is_string($item)) $item = mb_encode_numericentity($item, array (0x80, 0xffff, 0, 0xffff), 'UTF-8'); });
    return mb_decode_numericentity(json_encode($arr), array (0x80, 0xffff, 0, 0xffff), 'UTF-8');
}
$array = array("foo","bar");
$result = my_json_encode($array);
답변을 작성하시기 전에 로그인 해주세요.
전체 168
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT