Created
May 31, 2011 10:14
-
-
Save salathe/1000264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$apiBase = 'http://api.microsofttranslator.com/V2/Http.svc'; | |
$appId = 'yourappid'; | |
$text = 'Een hoge boom vangt veel wind'; | |
$streamContext = stream_context_create(array('http' => array( | |
'method' => 'POST', | |
'content' => '', | |
'header' => implode("\r\n", array('Content-Type: text/xml', 'Content-Length: 0')), | |
))); | |
libxml_set_streams_context($streamContext); | |
$bingResponse = simplexml_load_file( | |
"{$apiBase}/GetTranslations?appId={$appId}&from=&to=en&maxTranslations=1&text=".urlencode($text) | |
); | |
$language = (string) $bingResponse->From; | |
$inEnglish = (string) $bingResponse->Translations->TranslationMatch->TranslatedText; | |
var_dump( $language, $inEnglish ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$apiBase = 'http://api.microsofttranslator.com/V2/Http.svc'; | |
$appId = 'yourappid'; | |
$text = 'Een hoge boom vangt veel wind'; | |
$streamContext = stream_context_create(array('http' => array( | |
'method' => 'POST', | |
'content' => '', | |
'header' => implode("\r\n", array('Content-Type: text/xml', 'Content-Length: 0')), | |
))); | |
$bingResponse = simplexml_load_string( | |
file_get_contents( | |
"{$apiBase}/GetTranslations?appId={$appId}&from=&to=en&maxTranslations=1&text=".urlencode($text), | |
false, | |
$streamContext | |
) | |
); | |
$language = (string) $bingResponse->From; | |
$inEnglish = (string) $bingResponse->Translations->TranslationMatch->TranslatedText; | |
var_dump( $language, $inEnglish ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment