Foros del Web » Programando para Internet » PHP »

Variables PHP a Javascript

Estas en el tema de Variables PHP a Javascript en el foro de PHP en Foros del Web. Saludos, quiero hacer un rotador de texto con unas variables que tengo en un .txt que estan en PHP. Busque un ratador de texto y ...
  #1 (permalink)  
Antiguo 07/06/2007, 17:48
 
Fecha de Ingreso: septiembre-2006
Mensajes: 46
Antigüedad: 17 años, 8 meses
Puntos: 0
Variables PHP a Javascript

Saludos, quiero hacer un rotador de texto con unas variables que tengo en un .txt que estan en PHP. Busque un ratador de texto y quiero que el texto que rote sea el de esas variables, el scrip que va en el head es el siguiente.
-------------------------------------------------------
<script language="javascript" type="text/javascript">

var textos = new Array()
textos[0] = '<b>Texto de ejemplo para Texto Cambiante</b>'
textos[1] = '<b>Cambia cada 2 segundos aproximadamente</b>'
textos[2] = '<b>Puedes cambiar también su aspecto</b>'
textos[3] = '<b>¡Pruébalo!</b>'
var indice = 0

function CambiaTextoNAV() {
document.capa1.document.write( textos[indice] )
document.capa1.document.close()
if ( indice == 3 )
indice = 0
else
indice++
setTimeout( "CambiaTextoNAV()", 2000 )
}

function CambiaTextoIE() {
capa1.innerHTML = textos[indice]
if ( indice == 3 )
indice = 0
else
indice++
setTimeout( "CambiaTextoIE()", 2000 )
}

function CambiaTexto() {
document.getElementById("capa1").innerHTML = textos[indice]
if ( indice == 3 )
indice = 0
else
indice++
setTimeout( "CambiaTexto()", 2000 )
}

function Cambia() {
if (document.layers)
CambiaTextoNAV()
else if (document.all)
CambiaTextoIE()
else
CambiaTexto()
}

window.onload = Cambia;
if (document.captureEvents) { //N4 requiere invocar la funcion captureEvents
document.captureEvents(Event.LOAD)
}
</script>

----------------------------------------------------------
ya intente poner agregando ?> ?> entre el script y le doy un include para llamar a mis variables que estan en el txt, y en lugar pongo

var textos = new Array()
textos[0] = '<b>$texto1</b>'


pero no funciona. El texto que va en el body es


<!-- Visualizacion del texto -->
<script language="javascript" type="text/javascript">
if (document.layers) {
capa = '<p><layer id="capa1" top="110" left="120" width="35"></layer>'
} else {
capa = '<div id="capa1" style="position:relative"></div>'
}
document.write ( capa )
</script>


Si alguien me pudiera ayudar, se lo agradeceria
  #2 (permalink)  
Antiguo 07/06/2007, 18:18
Avatar de minkweb  
Fecha de Ingreso: septiembre-2005
Mensajes: 443
Antigüedad: 18 años, 8 meses
Puntos: 14
Re: Variables PHP a Javascript

bueno es simple.. sacas los textos del txt con php.. lo metes en una variable y lo metes a javascript asi

Código HTML:
<script>
textos[2] = '<b>'+<? echo $variablephp; ?>+'</b>'
</script> 
espero te sea útil
  #3 (permalink)  
Antiguo 08/06/2007, 09:53
 
Fecha de Ingreso: septiembre-2006
Mensajes: 46
Antigüedad: 17 años, 8 meses
Puntos: 0
Re: Variables PHP a Javascript

Lo he intentado de esta manera y no logro, el ¿<? ?> debe de ir entre el <script></script>? ¿o primero llamo a las varias y lugo pongo la sentencia del script?

Código PHP:
<?
include ("texto1.txt");
include (
"texto2.txt");
include (
"texto3.txt");
include (
"texto4.txt");

$textscript1 $texto1
$textscript2 
$texto2
$textscript3 
$texto3
$textscript4 
$texto4

<script language="javascript" type="text/javascript">

var 
textos = new Array()
textos[0] = '<b>'+<? echo $textscript1?>+'</b>'
textos[1] = '<b>'+<? echo $textscript2?>+'</b>'
textos[2] = '<b>'+<? echo $textscript3?>+'</b>'
textos[3] = '<b>'+<? echo $textscript4?>+'</b>'
var indice = 0

?>
  #4 (permalink)  
Antiguo 08/06/2007, 11:36
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: Variables PHP a Javascript

Código PHP:
<?php
include ("texto1.txt");
include (
"texto2.txt");
include (
"texto3.txt");
include (
"texto4.txt");

$textscript1 $texto1;
$textscript2 $texto2;
$textscript3 $texto3;
$textscript4 $texto4;
?>
<script language="javascript" type="text/javascript">
var textos = new Array();
textos[0] = '<b>'+<? echo $textscript1?>+'</b>';
textos[1] = '<b>'+<? echo $textscript2?>+'</b>';
textos[2] = '<b>'+<? echo $textscript3?>+'</b>';
textos[3] = '<b>'+<? echo $textscript4?>+'</b>';
var indice = 0;
</script>
  #5 (permalink)  
Antiguo 15/06/2007, 09:32
 
Fecha de Ingreso: septiembre-2006
Mensajes: 46
Antigüedad: 17 años, 8 meses
Puntos: 0
Re: Variables PHP a Javascript

Ya lo he intentado de mil maneras y nada. Consulte en otros sitios y prove con otros metodos, pero marca error de sitaxis.
  #6 (permalink)  
Antiguo 15/06/2007, 09:51
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Re: Variables PHP a Javascript

Hola blackmaster52x

Prueba así:

Código PHP:
textos[0] = '<b><? echo $textscript1?></b>';
textos[1] = '<b><? echo $textscript2?></b>';
textos[2] = '<b><? echo $textscript3?></b>';
textos[3] = '<b><? echo $textscript4?></b>';
Saludos,
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:23.