I have a form with an input textfield where I am storing a Javascript array in JSON format. This way, when I click the submit button, the server gets the information with PHP from the $_POST array. I noticed that I had to replace ‘[‘ and ‘]’ by ‘{‘ and ‘}’, however I can’t replace the from the JSON in PHP, the str_replace function does not execute this replacement.
Javascript code
let qrs = ["A", "B", "C"]; // Array with values
let jqrs = JSON.stringify(qrs); // The string obtained
input.val(jqrs); // Inserting the data in the input with JQuery
PHP file
$json_names = $_POST['plugin-assetlist-qr-text'];
str_replace('[', '{', $json_names);
str_replace(']', '}', $json_names);
str_replace("\", "/", $json_names); // This replacement isn't done
echo "{$json_names}<br><br>"; // returns for example {"A","B","C"}
I don’t know what to try. When the ” characters appeared in my echo instruction I thought it meant that the string contained and “.
1