Last active
July 16, 2023 13:57
-
-
Save MANOJ-M-01/95febf6c1787974810a2228e556bdf0e to your computer and use it in GitHub Desktop.
Oxford Dictionaries api cURL PHP API
This file contains hidden or 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 | |
echo '<br/> | |
<select name="source_lang" id="msource_lang0"> | |
<option value="en-gb"> en-gb </option> | |
<option value="en-us"> en-us </option> | |
<option value="es"> es </option> | |
<option value="fr"> fr </option> | |
<option value="gu"> gu </option> | |
<option value="hi"> hi </option> | |
<option value="lv"> lv </option> | |
<option value="ro"> ro </option> | |
<option value="sw"> sw </option> | |
<option value="ta"> ta </option> | |
</select> <br/>'; | |
$API_ID="your-app-id"; | |
$API_KEY = "your-apikey"; | |
$word_id = "water"; | |
$lang_code = "en-us"; | |
$fields = "definitions,examples,pronunciations"; | |
$strictMatch = "false"; | |
$ch = curl_init(); | |
$url="https://od-api.oxforddictionaries.com:443/api/v2/entries/".$lang_code."/".$word_id ."?fields=".$fields."&strictMatch=".$strictMatch; | |
curl_setopt($ch,CURLOPT_URL,$url); | |
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); | |
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
'app_id: e82e9001', | |
'app_key: 0e2535ed53c6f7c6e8ee28ec0b5ed4bf' | |
)); | |
$rslt=curl_exec($ch); | |
$s=json_decode($rslt); | |
//print_r(json_decode($rslt)); | |
//echo $s->results[1]->original_title; | |
$error=$s->error??NULL; | |
echo $error; | |
$message=$s->message??NULL; | |
echo $message; | |
if (!$error && !$message) { | |
foreach ($s->results as $mydata) { | |
echo $mydata->id ."<br/>"; | |
foreach ($mydata->lexicalEntries as $mydata2) { | |
echo $mydata2->language ."<br/>"; | |
/* | |
$lexicalCategory_id=$mydata2->lexicalCategory->id??NULL; | |
$lexicalCategory_text=$mydata2->lexicalCategory->text??NULL; | |
echo $lexicalCategory_text ." "; | |
echo "(".$lexicalCategory_id .")<br/>"; | |
*/ | |
foreach ($mydata2->entries as $mydata3) { | |
foreach ($mydata3->pronunciations as $mydata4) { | |
$audio=$mydata4->audioFile??null; | |
$audio2=$audio?$audio:1; | |
if (!($audio2==1)) { | |
echo "<audio controls> <source src=". $audio2." type='audio/mpeg'> Your browser does not support the audio tag. | |
</audio> <br/>"; | |
} | |
echo $mydata4->phoneticSpelling ."<br/>"; | |
} | |
foreach ($mydata3->senses as $mydata4) { | |
foreach ($mydata4->definitions as $mydata5) { | |
echo $mydata5 ."<br/>"; | |
} | |
/*Definition example*/ | |
$examples=$mydata4->examples??NULL; | |
if (!($examples==NULL)) { | |
foreach ($mydata4->examples as $mydata8) { | |
echo "Definition example :".$mydata8->text ."<br/>"; | |
} | |
} | |
/*Sub Definition */ | |
$subsenses=$mydata4->subsenses??NULL; | |
if (!($subsenses==NULL)) { | |
foreach ($mydata4->subsenses as $mydata6) { | |
foreach ($mydata6->definitions as $mydata7) { | |
echo "Sub Definition :".$mydata7 ."<br/>"; | |
} | |
$Sub_examples=$mydata6->examples??NULL; | |
if (!($Sub_examples==null)) { | |
foreach ($mydata6->examples as $mydata9) { | |
echo "Sub Definition example :".$mydata9->text ."<br/>"; | |
} | |
} | |
} | |
} | |
/* | |
*/ | |
} | |
} | |
} | |
} | |
} | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment