PHP/cURL image recognition intergration using Imagga service
up vote
0
down vote
favorite
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 |
up vote
0
down vote
favorite
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 at 12:38
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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 at 12:38
Loek
2,806925
2,806925
asked Nov 19 at 12:34
Advanced SEO
222316
222316
Possible duplicate of How do I extract data from JSON with PHP?
– Loek
Nov 19 at 12:38
add a comment |
Possible duplicate of How do I extract data from JSON with PHP?
– Loek
Nov 19 at 12:38
Possible duplicate of How do I extract data from JSON with PHP?
– Loek
Nov 19 at 12:38
Possible duplicate of How do I extract data from JSON with PHP?
– Loek
Nov 19 at 12:38
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
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 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 at 16:20
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 at 9:36
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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 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 at 16:20
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 at 9:36
add a comment |
up vote
1
down vote
accepted
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 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 at 16:20
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 at 9:36
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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 at 16:19
answered Nov 19 at 12:57
myxaxa
53736
53736
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 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 at 16:20
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 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 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 at 16:20
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 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 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 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 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 at 16:20
1
1
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 at 17:04
Thank you for your answer, it is working fine, also thank you for more info.
– Advanced SEO
Nov 19 at 17:04
np problem at all ^_^
– myxaxa
Nov 20 at 9:36
np problem at all ^_^
– myxaxa
Nov 20 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 at 12:38