Re: algo parecido a una plantilla

From: Date: Tue, 28 Jun 2005 07:49:24 +0000
Subject: Re: algo parecido a una plantilla
References: 1  Groups: php.general.es 
Request: Send a blank email to general-es+get-55218@lists.php.net to get a copy of this message
A ver Carlos, tienes una confusión. Los includes de PHP procesan como PHP lo que está entre <?php y ?> Así que lo que puedes hacer es esto: fichero "tal.php" <? $variable1="Hola que tal"; $variable2="hello word"; require ("ver.html"); ?> fichero "ver.html" <?php print <<<fin <html> <head> <title>$variable1<title> <head> <body> <center>$variable2<center> <body> <html> fin; /* ten en cuenta que si después del <<<fin o bien antes del fin; pones algo (aunque solo sea un espacio o un tabulador) no funcionará. Pero a mi me gusta más esta solución (es más limpia): fichero "tal.php" <? $variable1="Hola que tal"; $variable2="hello word"; //leo las lineas del fichero plantilla $filas=file("ver.html"); //meto todo el array de lineas en una sola variable $codigo = implode("", $filas); //reemplazamos las variables $codigo=str_replace("#variable1#", $variable1, $codigo); $codigo=str_replace("#variable2#", $variable2, $codigo); //imprimimos el código print $codigo; ?> fichero "ver.html" <html> <head> <title>#variable1#<title> <head> <body> <center>#variable2#<center> <body> <html> */ ?> On 6/27/05, Carlos Niño Alonso <carlos@ineteca.com> wrote: > > hola lista, quiero hacer una cosa como esta: > > > Desde un fichero, calculo una serie de variables pero quiero sacarlas en > un > fichero html, muy parecido a lo que seria una plantilla.. > > > fichero "tal.php" > <? > variable1 "Hola que tal"; > variable2 "hello word"; > require ("ver.html"); > ?> > > > fichero "ver.html" > <html> > <head> > <title>variable1<title> > <head> > <body> > <center>variale2<center> > <body> > <html> > > el caso es que si en ver.html no lo tengo entre un echo no funciona, ¿que > puedo > hacer? > > ------------------------------------------- > Carlos Alonso Niño > Ineteca > C/ Melquiades Álvarez nº20 3 puerta 2 > 33003 - Oviedo (Asturias) > carlos@ineteca.com > ------------------------------------------- > > -- > PHP Spanish Localization Talk Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general.es (#55218) next »