Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
Using JS array values as PHP array values

I cannot find a solution to my question, I read the hints of server-side and client-side issues already.

  1. 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>
    
  2. 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']
    
  3. I try to use this js array in php.

     <?php
     $test0 = "<script>document.writeln(myList);</script>";
    
  4. I echo the $test0, it works, I get the apple1,apple2,apple3 values:

     echo $test0;
     //apple1,apple2,apple3
    
  5. 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
    
  6. 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
    
  7. I echo the $test2 array values, it works, I get the values:

     foreach($test2 as $value){
     echo $value;
     }
     ?>  
     //apple1,apple2,apple3
    
  8. 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!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda