• Miércoles 15 de Mayo de 2024, 23:22

Autor Tema:  Problema Con Pgm En Php-cli  (Leído 1447 veces)

CUBX

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Problema Con Pgm En Php-cli
« en: Miércoles 24 de Octubre de 2007, 21:09 »
0
Disculpen amigos,  hace unos dias que lucho en vano tratando de imprimir (en pantalla) strings en PHP-CLI bajo WINDOWS XP. He probado todo, print_r , ciclos, forzar con settype a string  y siempre los muestra vacios,…

Aquí les dejo un codigo y su salida correspondiente, se agradecera alguna solucion


Código: Text
  1.  
  2. <?php
  3. fwrite(STDOUT, "Ingrese un numero natural\n");
  4.  
  5. $num2=fgets(STDIN);
  6.  
  7. $arreglo = Array();
  8. settype($arreglo, "array");
  9.  
  10. $i=0;
  11. while ($i < $num2) {
  12.  
  13. $arreglo [i] = $i;
  14.  
  15. $i++;
  16.  
  17. }
  18.  
  19. fwrite (STDOUT, "El arreglo es: \n");
  20.  
  21. $j=0;
  22. while ($j < count ($arreglo) ) {
  23. print $arreglo[$j];
  24. $j++;
  25. }
  26.  
  27. fwrite (STDOUT, "El dump del arreglo es: \n");
  28. var_dump($arreglo);
  29.  
  30. ?>
  31.  
  32.  
  33.  

Código: Text
  1.  SALIDA:
  2.  
  3. E:\php5>php arreglo.php
  4. Ingrese un numero natural
  5. 5
  6. El arreglo es:
  7. El dump del arreglo es:
  8. array(1) {
  9.   ["i"]=>
  10.   int(4)
  11. }
  12.  
  13.  
[size=109]When the sun has wept upon the waveless lake And the mists steal in with ease Covened wolves are their eerie dissonant napes In adoration of the moon and thee[/size] [size=109]                                                       "They call as I to thee...."[/size]

-DriverOp-

  • Miembro activo
  • **
  • Mensajes: 81
    • Ver Perfil
Re: Problema Con Pgm En Php-cli
« Respuesta #1 en: Jueves 25 de Octubre de 2007, 04:01 »
0
En la línea 12, donde dice:
Código: Text
  1. $arreglo [i] = $i;
  2.  
"i" no es una variable, es una constante, creo que quisiste poner:
Código: Text
  1. $arreglo[$i] = $i;
  2.  
Y esto:
Código: Text
  1. print $arreglo[$j];
  2.  
Es mejor ponerlo así:
Código: Text
  1. fwrite (STDOUT, $arreglo[$j]."\n");
  2.  

Saludos.

CUBX

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Re: Problema Con Pgm En Php-cli
« Respuesta #2 en: Jueves 25 de Octubre de 2007, 19:50 »
0
Muchisimas gracias, no entiendo como se me paso un error tan ........!

Es que esto del $ para las variables es nuevo para mi.

Salu2
[size=109]When the sun has wept upon the waveless lake And the mists steal in with ease Covened wolves are their eerie dissonant napes In adoration of the moon and thee[/size] [size=109]                                                       "They call as I to thee...."[/size]

-DriverOp-

  • Miembro activo
  • **
  • Mensajes: 81
    • Ver Perfil
Re: Problema Con Pgm En Php-cli
« Respuesta #3 en: Viernes 26 de Octubre de 2007, 04:05 »
0
No te preocupes, a mi también me pasa de vez en cuando, sobre todo cuando tienes dos o tres lenguajes en la cabeza como es mi caso :D.