Answer the question
In order to leave comments, you need to log in
Extract value from json?
When checking the recaptcha on the server, a response comes from Google:
{"success": false,"error-codes": ["invalid-input-response" ]}
$recaptcha = json_decode($recaptcha);
var_dump($recaptcha):
object(stdClass)#6 (2) {
["success"]=>
bool(false)
["error-codes"]=>
array(1) {
[0]=>
string(22) "invalid-input-response"
}
}
$recaptcha->success
$recaptcha->error-codes
outputs 0 and the integer type $recaptcha->error-codes[0]
Answer the question
In order to leave comments, you need to log in
The problem is getting around the invalid property name (because a hyphen is used).
We use the magic of naming a class property through a variable.
$recaptcha_property_name = 'error-codes';
echo $recaptcha->$recaptcha_property_name[0];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question