I want to extract and run PHP functions from a JSON string variable. my string variable is something like this :
$str = '"field_table_id": {
"element_name": "select",
"title": "some_title",
"attributes": {
"id": "field_table_id"
},
"options": {
"values" : "@php_function ['function1', 'arg1', 'arg2', 'arg3'] @end_php",
"titles" : "@php_function ['function1', 'arg1', 'arg2', 'arg3'] @end_php"
}
}';
how can I do this?
When I ask this question I think the following answer is right but I found a better solution now.
I write a simple function for this. you can use this function in your codes.usage:
My new solution is :
In JSON syntax curly braces hold objects and square brackets hold arrays suppose I change the JSON to the following string :
I want replace
with a PHP array like this as JSON object:
and
with this PHP array as JSON array:
the following PHP function to this for us
usage:
Test Code on PHP Sandbox
Let me know if you have any suggestions or corrections.