PHP/cURL image recognition intergration using Imagga service
I am trying to get image tags from Imagga image recognition (artificial intelligence service, new V2 version) using cURL and PHP.
I managed to get valid responce, cURL body responce looks like this:
{
"result":{
"tags":[
{"confidence":100,"tag":{"en":"pink"}},
{"confidence":92.6405181884766,"tag":{"en":"petal"}},
{"confidence":69.8676071166992,"tag":{"en":"flower"}},
{"confidence":54.1640663146973,"tag":{"en":"bloom"}}
]
}
,"status":{"text":"","type":"success"}
}
I tried to foreach tags, but I am having trouble.
$response = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$body = substr($response, $header_size);
$header = substr($response, 0, $header_size);
$rows = explode("n", $header);
$err = curl_error($curl);
curl_close($curl);
$resp = json_decode( $body, true );
if ($err) {echo $err; } else {
// foreach thought tags, and if tag confidence is above 60, than echo it, do something with it...
}
How to echo some tag if tag confidence is above 60?
php json curl
add a comment |
I am trying to get image tags from Imagga image recognition (artificial intelligence service, new V2 version) using cURL and PHP.
I managed to get valid responce, cURL body responce looks like this:
{
"result":{
"tags":[
{"confidence":100,"tag":{"en":"pink"}},
{"confidence":92.6405181884766,"tag":{"en":"petal"}},
{"confidence":69.8676071166992,"tag":{"en":"flower"}},
{"confidence":54.1640663146973,"tag":{"en":"bloom"}}
]
}
,"status":{"text":"","type":"success"}
}
I tried to foreach tags, but I am having trouble.
$response = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$body = substr($response, $header_size);
$header = substr($response, 0, $header_size);
$rows = explode("n", $header);
$err = curl_error($curl);
curl_close($curl);
$resp = json_decode( $body, true );
if ($err) {echo $err; } else {
// foreach thought tags, and if tag confidence is above 60, than echo it, do something with it...
}
How to echo some tag if tag confidence is above 60?
php json curl
Possible duplicate of How do I extract data from JSON with PHP?
– Loek
Nov 19 '18 at 12:38
add a comment |
I am trying to get image tags from Imagga image recognition (artificial intelligence service, new V2 version) using cURL and PHP.
I managed to get valid responce, cURL body responce looks like this:
{
"result":{
"tags":[
{"confidence":100,"tag":{"en":"pink"}},
{"confidence":92.6405181884766,"tag":{"en":"petal"}},
{"confidence":69.8676071166992,"tag":{"en":"flower"}},
{"confidence":54.1640663146973,"tag":{"en":"bloom"}}
]
}
,"status":{"text":"","type":"success"}
}
I tried to foreach tags, but I am having trouble.
$response = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$body = substr($response, $header_size);
$header = substr($response, 0, $header_size);
$rows = explode("n", $header);
$err = curl_error($curl);
curl_close($curl);
$resp = json_decode( $body, true );
if ($err) {echo $err; } else {
// foreach thought tags, and if tag confidence is above 60, than echo it, do something with it...
}
How to echo some tag if tag confidence is above 60?
php json curl
I am trying to get image tags from Imagga image recognition (artificial intelligence service, new V2 version) using cURL and PHP.
I managed to get valid responce, cURL body responce looks like this:
{
"result":{
"tags":[
{"confidence":100,"tag":{"en":"pink"}},
{"confidence":92.6405181884766,"tag":{"en":"petal"}},
{"confidence":69.8676071166992,"tag":{"en":"flower"}},
{"confidence":54.1640663146973,"tag":{"en":"bloom"}}
]
}
,"status":{"text":"","type":"success"}
}
I tried to foreach tags, but I am having trouble.
$response = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$body = substr($response, $header_size);
$header = substr($response, 0, $header_size);
$rows = explode("n", $header);
$err = curl_error($curl);
curl_close($curl);
$resp = json_decode( $body, true );
if ($err) {echo $err; } else {
// foreach thought tags, and if tag confidence is above 60, than echo it, do something with it...
}
How to echo some tag if tag confidence is above 60?
php json curl
php json curl
edited Nov 19 '18 at 12:38


Loek
2,869925
2,869925
asked Nov 19 '18 at 12:34
Advanced SEO
227316
227316
Possible duplicate of How do I extract data from JSON with PHP?
– Loek
Nov 19 '18 at 12:38
add a comment |
Possible duplicate of How do I extract data from JSON with PHP?
– Loek
Nov 19 '18 at 12:38
Possible duplicate of How do I extract data from JSON with PHP?
– Loek
Nov 19 '18 at 12:38
Possible duplicate of How do I extract data from JSON with PHP?
– Loek
Nov 19 '18 at 12:38
add a comment |
1 Answer
1
active
oldest
votes
just use foreach
<?php
$body = '{
"result":{
"tags":[
{"confidence":100,"tag":{"en":"pink"}},
{"confidence":92.6405181884766,"tag":{"en":"petal"}},
{"confidence":69.8676071166992,"tag":{"en":"flower"}},
{"confidence":54.1640663146973,"tag":{"en":"bloom"}}
]
}
,"status":{"text":"","type":"success"}
}';
$resp = json_decode( $body, true );
foreach ($resp['result']['tags'] ?? $tags as $tag) {
if (
($confidence = $tag['confidence'] ?? null)
&& $confidence >= 60
&& ($tagName = $tag['tag']['en'] ?? null)
) {
echo $tagName . "rn";
}
}
var_dump($tag) shows array like this: array(2) { ["confidence"]=> float(100) ["tag"]=> array(1) { ["en"]=> string(5) "pink" } } How to echo just tag name "pink"? Could you please update your answer to echo just tag name, if confidence is above 60?
– Advanced SEO
Nov 19 '18 at 15:44
1
done. but you should look on php.net/manual/en/control-structures.foreach.php and php.net/manual/en/language.types.array.php ^_^
– myxaxa
Nov 19 '18 at 16:20
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 '18 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 '18 at 9:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374780%2fphp-curl-image-recognition-intergration-using-imagga-service%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
just use foreach
<?php
$body = '{
"result":{
"tags":[
{"confidence":100,"tag":{"en":"pink"}},
{"confidence":92.6405181884766,"tag":{"en":"petal"}},
{"confidence":69.8676071166992,"tag":{"en":"flower"}},
{"confidence":54.1640663146973,"tag":{"en":"bloom"}}
]
}
,"status":{"text":"","type":"success"}
}';
$resp = json_decode( $body, true );
foreach ($resp['result']['tags'] ?? $tags as $tag) {
if (
($confidence = $tag['confidence'] ?? null)
&& $confidence >= 60
&& ($tagName = $tag['tag']['en'] ?? null)
) {
echo $tagName . "rn";
}
}
var_dump($tag) shows array like this: array(2) { ["confidence"]=> float(100) ["tag"]=> array(1) { ["en"]=> string(5) "pink" } } How to echo just tag name "pink"? Could you please update your answer to echo just tag name, if confidence is above 60?
– Advanced SEO
Nov 19 '18 at 15:44
1
done. but you should look on php.net/manual/en/control-structures.foreach.php and php.net/manual/en/language.types.array.php ^_^
– myxaxa
Nov 19 '18 at 16:20
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 '18 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 '18 at 9:36
add a comment |
just use foreach
<?php
$body = '{
"result":{
"tags":[
{"confidence":100,"tag":{"en":"pink"}},
{"confidence":92.6405181884766,"tag":{"en":"petal"}},
{"confidence":69.8676071166992,"tag":{"en":"flower"}},
{"confidence":54.1640663146973,"tag":{"en":"bloom"}}
]
}
,"status":{"text":"","type":"success"}
}';
$resp = json_decode( $body, true );
foreach ($resp['result']['tags'] ?? $tags as $tag) {
if (
($confidence = $tag['confidence'] ?? null)
&& $confidence >= 60
&& ($tagName = $tag['tag']['en'] ?? null)
) {
echo $tagName . "rn";
}
}
var_dump($tag) shows array like this: array(2) { ["confidence"]=> float(100) ["tag"]=> array(1) { ["en"]=> string(5) "pink" } } How to echo just tag name "pink"? Could you please update your answer to echo just tag name, if confidence is above 60?
– Advanced SEO
Nov 19 '18 at 15:44
1
done. but you should look on php.net/manual/en/control-structures.foreach.php and php.net/manual/en/language.types.array.php ^_^
– myxaxa
Nov 19 '18 at 16:20
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 '18 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 '18 at 9:36
add a comment |
just use foreach
<?php
$body = '{
"result":{
"tags":[
{"confidence":100,"tag":{"en":"pink"}},
{"confidence":92.6405181884766,"tag":{"en":"petal"}},
{"confidence":69.8676071166992,"tag":{"en":"flower"}},
{"confidence":54.1640663146973,"tag":{"en":"bloom"}}
]
}
,"status":{"text":"","type":"success"}
}';
$resp = json_decode( $body, true );
foreach ($resp['result']['tags'] ?? $tags as $tag) {
if (
($confidence = $tag['confidence'] ?? null)
&& $confidence >= 60
&& ($tagName = $tag['tag']['en'] ?? null)
) {
echo $tagName . "rn";
}
}
just use foreach
<?php
$body = '{
"result":{
"tags":[
{"confidence":100,"tag":{"en":"pink"}},
{"confidence":92.6405181884766,"tag":{"en":"petal"}},
{"confidence":69.8676071166992,"tag":{"en":"flower"}},
{"confidence":54.1640663146973,"tag":{"en":"bloom"}}
]
}
,"status":{"text":"","type":"success"}
}';
$resp = json_decode( $body, true );
foreach ($resp['result']['tags'] ?? $tags as $tag) {
if (
($confidence = $tag['confidence'] ?? null)
&& $confidence >= 60
&& ($tagName = $tag['tag']['en'] ?? null)
) {
echo $tagName . "rn";
}
}
edited Nov 19 '18 at 16:19
answered Nov 19 '18 at 12:57
myxaxa
56236
56236
var_dump($tag) shows array like this: array(2) { ["confidence"]=> float(100) ["tag"]=> array(1) { ["en"]=> string(5) "pink" } } How to echo just tag name "pink"? Could you please update your answer to echo just tag name, if confidence is above 60?
– Advanced SEO
Nov 19 '18 at 15:44
1
done. but you should look on php.net/manual/en/control-structures.foreach.php and php.net/manual/en/language.types.array.php ^_^
– myxaxa
Nov 19 '18 at 16:20
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 '18 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 '18 at 9:36
add a comment |
var_dump($tag) shows array like this: array(2) { ["confidence"]=> float(100) ["tag"]=> array(1) { ["en"]=> string(5) "pink" } } How to echo just tag name "pink"? Could you please update your answer to echo just tag name, if confidence is above 60?
– Advanced SEO
Nov 19 '18 at 15:44
1
done. but you should look on php.net/manual/en/control-structures.foreach.php and php.net/manual/en/language.types.array.php ^_^
– myxaxa
Nov 19 '18 at 16:20
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 '18 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 '18 at 9:36
var_dump($tag) shows array like this: array(2) { ["confidence"]=> float(100) ["tag"]=> array(1) { ["en"]=> string(5) "pink" } } How to echo just tag name "pink"? Could you please update your answer to echo just tag name, if confidence is above 60?
– Advanced SEO
Nov 19 '18 at 15:44
var_dump($tag) shows array like this: array(2) { ["confidence"]=> float(100) ["tag"]=> array(1) { ["en"]=> string(5) "pink" } } How to echo just tag name "pink"? Could you please update your answer to echo just tag name, if confidence is above 60?
– Advanced SEO
Nov 19 '18 at 15:44
1
1
done. but you should look on php.net/manual/en/control-structures.foreach.php and php.net/manual/en/language.types.array.php ^_^
– myxaxa
Nov 19 '18 at 16:20
done. but you should look on php.net/manual/en/control-structures.foreach.php and php.net/manual/en/language.types.array.php ^_^
– myxaxa
Nov 19 '18 at 16:20
1
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 '18 at 17:04
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 '18 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 '18 at 9:36
np problem at all ^_^
– myxaxa
Nov 20 '18 at 9:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374780%2fphp-curl-image-recognition-intergration-using-imagga-service%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of How do I extract data from JSON with PHP?
– Loek
Nov 19 '18 at 12:38