I cannot find a solution to my question, I read the hints of server-side and client-side issues already.
I have a js script that loads the values of a js array which is stored in localStorage, here is the code:
<script>
var myList = JSON.parse(localStorage.getItem('myList', '[]'));
console.log(myList);
</script>
I get the content of the myList array values stored locally. The values of this array are separated by a comma (,) like this:
myList ['apple1', 'apple2', 'apple3']
I try to use this js array in php.
<?php
$test0 = "<script>document.writeln(myList);</script>";
I echo the $test0, it works, I get the apple1,apple2,apple3 values:
echo $test0;
//apple1,apple2,apple3
I change $test0 to a string (anyway it should be a string originally) and then I check whether it´s really a string, it works, it´s a string:
$test1 = strval($test0);
echo is.string($test1);
// 1
I explode the string $test1 into the $test2 array and then check whether $test2 is an array, it works, $test2 is an array;
$test2 = explode(',',$test1,0);
echo is_array($test2);
// 1
I echo the $test2 array values, it works, I get the values:
foreach($test2 as $value){
echo $value;
}
?>
//apple1,apple2,apple3
But, if I try to use the substr() function to this $value in order to return specific characters of each value of the $value array, I get the substracted string of the $test0 variable (ript>document.writeln(myList);):
foreach($test2 as $value){
echo substr($value,3);
}
// ript>document.writeln(myList);
Why does not work the substr() function in this case?
Thank you for your help!