Answer the question
In order to leave comments, you need to log in
How to wean json_encode in php to escape the backslash "\"?
Hello!
The situation is, there is a multidimensional php array, it has regular expressions (in string type), all this is transferred to javascript using json.
But php finds backslashes in the string and escapes them, and as a result we get two backslashes :(
Code, for playing around:
<?php $array = [
['regExp' => '^[\+]{1}[7]{1}[\d]{10}$'],
['regExp' => '^\+\d{7,15}$'],
['regExp' => '([45]{1}[\d]{15}|[6]{1}[\d]{17})$'],
]; ?>
<script> var test = JSON.parse('<?= json_encode($array) ?>');
console.log(test); </script>
Answer the question
In order to leave comments, you need to log in
json_encode($str, JSON_UNESCAPED_SLASHES);
As they say here - "banned in Google?". stackoverflow.com/questions/10210338/json-encode-e...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question