JSON Decode via PHP [duplicate] - javascript

This question already has answers here:
How can I get useful error messages in PHP?
(41 answers)
PHP parse/syntax errors; and how to solve them
(20 answers)
How to extract and access data from JSON with PHP?
(1 answer)
Closed 3 years ago.
I have a JSON file, but I can't decode it like any other JSON file.
Where am I making a mistake?
$jsonData = '[[[],[{"file_id":"2_U_3","sub_file_id":"2_U_3_1","option_file":[0,3.44827586207],"file_votes":1}],[],[],[],[]],{}]';
$jsonDec = json_decode($jsonData, TRUE);
echo $jsonDec["file_id"] . " = " . $jsonDec["option_file"][2];
Result: empty screen

Related

Pass a variable from JS to PHP for MYSQL query without ajax [duplicate]

This question already has answers here:
How do I pass JavaScript variables to PHP?
(16 answers)
How can I use a JavaScript variable as a PHP variable? [duplicate]
(7 answers)
Closed 11 months ago.
Hi I need to pass a JS variable to PHP that can be used in a MYSQL query
i tried with
$varPQR = "<script> document.writeln(IdLocalStorage); </script>"; echo $varPQR;
$queryGetPqr = "SELECT * FROM {$wpdb->prefix}sfcwp_pqrs WHERE codigo_queja = {$varPQR}";
didn't work
Use form and hidden input to pass data from client to server

Text Array to Array in Javascript [duplicate]

This question already has answers here:
Parse JSON in JavaScript? [duplicate]
(16 answers)
Closed 3 years ago.
I need convert from data = "[[0,1], [1,1]]" to data = [[0,1], [1,1]] in javascript, remove double quotes . It's possible?
Thanks
Just use the JSON object:
data = JSON.parse("[[0,1], [1,1]]"); // data === [[0,1], [1,1]]

JS code into PHP code [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
I can not add JS code into PHP code
JavaScript File:
$.each(data.data,function(i,modul){
tb.append("<p><?php if (!is_dir($rootPath . '/Includes/'" + value.id+ "'")) { ?> <span>Test</span><?php } else { ?> <span>Test</span><?php } ?></p>"});
This line:
' + value.id+ ' = This is a JS code
Where do I make mistakes?
Thanks

How can I remove a key from JSON in PHP? [duplicate]

This question already has answers here:
How to extract and access data from JSON with PHP?
(1 answer)
How to filter an array by a condition
(9 answers)
Closed 5 years ago.
How can I remove the key "src" from this JSON if it is found in the array?
$json = '[{"label":"360","file":"http://aaa","src":"http://aaa"},
{"label":"480","file":"http://bbb","src":"http://bbb"},
{"label":"720","file":"http://ccc","src":"http://ccc"},
{"label":"1080","file":"http://ddd","src":"http://ddd"}]';
The desired end result is this:
$json = '[{"label":"360","file":"http://aaa"},
{"label":"480","file":"http://bbb"},
{"label":"720","file":"http://ccc"},
{"label":"1080","file":"http://ddd"}]';
Well assuming your json was correct (the above isn't as it's missing [] around it), corrected below.
$json = '[{"label":"360","file":"http://aaa","src":"http://aaa"},{"label":"480","file":"http://bbb","src":"http://bbb"},{"label":"720","file":"http://ccc","src":"http://ccc"},{"label":"1080","file":"http://ddd","src":"http://ddd"}]';
$decoded = json_decode($json, true);
foreach($decoded as $id => $row) {
unset($row[$id]['src']);
}
$json = json_encode($decoded);

I need to get jquery this.val() value into PHP at runtime [duplicate]

This question already has answers here:
Access a JavaScript variable from PHP
(9 answers)
What is the difference between client-side and server-side programming?
(3 answers)
Closed 5 years ago.
Is there a way to get the jquery this.val() read into PHP at runtime?
I have a dynamic push of data and need to run a SQL statement that depends on the jquery value of this.val() - so something like
<?php $sql = "select * from table where id = " . this.val(); ?>
No, becouse PHP can't read user's DOM.
You need to make an ajax request to send the data to the server.
jquery.ajax

Categories

Resources