2016-07-21 4 views
0

私はMicrosoft Congnitive WebLMを使用して単語の単語を分割し、cURL要求全体を出力しています。結果の使用方法を理解できません。私が使用しているcURLが全体の応答を出力しています

コード:

$word = 'iwansttobreakfree'; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 
    "https://api.projectoxford.ai/text/weblm/v1.0/breakIntoWords?model=query&text=" . $word); 
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, ""); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Ocp-Apim-Subscription-Key: [subscription key removed for stack overflow]" 
)); 

$result = curl_exec($ch); 

curl_close($ch); 

var_dump($result); 

結果の私は

HTTP/1.1 200 OK 
Cache-Control: no-cache 
Pragma: no-cache 
Content-Length: 320 
Content-Type: application/json; charset=utf-8 
Expires: -1 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
apim-request-id: ef73d48d-ab35-4fa5-a346-c57339415824 
Date: Thu, 21 Jul 2016 20:00:12 GMT 

{"candidates":[{"words":"i want to break free","probability":-7.1759999999999993},{"words":"iwant to break free","probability":-9.1660000000000021},{"words":"i want to breakfree","probability":-9.547},{"words":"i wan t to break free","probability":-9.8390000000000022},{"words":"iwanttobreakfree","probability":-9.877}]} 
-------- 
bool(true) 

は、誰もが、私は全体の出力を行うと、結果のJSONを使用する方法を知っていているそうだということcURLの応答?

答えて

1

:ドキュメントをチェックアウト

curl_setopt($ch, CURLOPT_HEADER, false); 

enter image description here

:これに

curl_setopt($ch, CURLOPT_HEADER, true); 

を:/

CURLOPT_RETURNTRANSFERtrueと設定し、CURLOPT_HEADERfalseに設定すると、json文字列が返されます。

これは新しいコードです:

この、その結果
$word = 'iwanttobreakfree'; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 
    "https://api.projectoxford.ai/text/weblm/v1.0/breakIntoWords?model=query&text=" . $word); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_POST, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_POSTFIELDS, ""); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Ocp-Apim-Subscription-Key: [key removed for stack overflow]" 
)); 

$result = curl_exec($ch); 

curl_close($ch); 

echo "\n--------\n"; 

$json = json_decode($result); 
var_dump($json); 

object(stdClass)#6 (1) { 
    ["candidates"]=> 
    array(5) { 
    [0]=> 
    object(stdClass)#1 (2) { 
     ["words"]=> 
     string(20) "i want to break free" 
     ["probability"]=> 
     float(-7.176) 
    } 
    [1]=> 
    object(stdClass)#2 (2) { 
     ["words"]=> 
     string(19) "iwant to break free" 
     ["probability"]=> 
     float(-9.166) 
    } 
    [2]=> 
    object(stdClass)#3 (2) { 
     ["words"]=> 
     string(19) "i want to breakfree" 
     ["probability"]=> 
     float(-9.547) 
    } 
    [3]=> 
    object(stdClass)#4 (2) { 
     ["words"]=> 
     string(21) "i wan t to break free" 
     ["probability"]=> 
     float(-9.839) 
    } 
    [4]=> 
    object(stdClass)#5 (2) { 
     ["words"]=> 
     string(16) "iwanttobreakfree" 
     ["probability"]=> 
     float(-9.877) 
    } 
    } 
} 
3

あなたは、この設定する必要があります:私は、本当に愚かな過ちをそれを考え出しhttp://php.net/manual/en/function.curl-setopt.php

+0

笑、私はそれはそれははっきりしていた醸造をした後、それらの 'コードblock'モーメントのの一つだったと思います:) –

+1

いつも私に起こります。 –

関連する問題