Foros del Web » Creando para Internet » Diseño web »

heredoc

Estas en el tema de heredoc en el foro de Diseño web en Foros del Web. Alguien podría decirme si puedo usar heredoc para solucionar el siguiente problema: En inicio.php tenemos: <? require ("pagina.inc"); $paginaInicio = new Pagina(); $paginaInicio -> SetContenidos("<table ...
  #1 (permalink)  
Antiguo 24/08/2010, 16:20
 
Fecha de Ingreso: agosto-2010
Mensajes: 4
Antigüedad: 13 años, 7 meses
Puntos: 0
heredoc

Alguien podría decirme si puedo usar heredoc para solucionar el siguiente problema:

En inicio.php tenemos:

<?
require ("pagina.inc");

$paginaInicio = new Pagina();

$paginaInicio -> SetContenidos("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">
<tr>
<th bgcolor=\"#000000\" scope=\"col\"><img src=\"Images/cuerpo.png\" width=\"780\" height=\"449\"></th>
</tr>
</table>"
);
$paginaInicio -> Mostrar();
?>

Dentro de SetContenidos tenemos codigo html, pero es necesario poner la barra invertida (\) antes de las comillas y otros simbolos para que php lo interprete correctamente, mi pregunta es:


El código con los contenidos que quiero incluir es bastante largo, ¿exite la prosibilidad de pasar el codigo html sin tener que poner la \ previamente a todas las comillas?

Muchas gracias por adelantado.



El archivo Pagina.inc es:

<?
class Pagina
{

// atributos de la clase Pagina
var $contenido;
var $titulo = "Multi Librería Online";
var $palabrasClave = "Librería Online, Aquí pondremos las palabras clave,
Podemos personalizarlas para cada página";
var $botones = array( "Inicio" => "inicio.php",
"Contacto" => "contacto.php",
"Servicios" => "servicios.php",
"Mapa Sitio" => "mapa.php"
);

// operaciones de la clase Pagina

function SetContenidos($nuevosContenidos)
{
$this->contenidos = $nuevosContenidos;
}

function SetTitulo($nuevoTitulo)
{
$this->titulo = $nuevoTitulo;
}

function SetPalabrasClave($nuevasPalabrasClave)
{
$this->palabrasClave = $nuevasPalabrasClave;
}

function SetBotones($nuevosBotones)
{
$this->botones = $nuevosBotones;
}

function Mostrar()
{
echo "<html>\n<head>\n";
$this -> MostrarTitulo();
$this -> MostrarPalabrasClave();
$this -> MostrarEstilos();
echo "</head>\n<body>\n";
$this -> MostrarCabecera();
$this -> MostrarMenu($this->botones);
echo $this->contenidos;
$this -> MostrarFooter();
echo "</body>\n</html>\n";
}

function MostrarTitulo()
{
echo "<titulo> $this->titulo </titulo>";
}

function MostrarPalabrasClave()
{
echo "<META name=\"palabrasClave\" contenidos=\"$this->palabrasClave\">";
}

function MostrarEstilos()
{
?>
<style>
body {
background-color: #000000;
}
h1 {color:white; font-size:12pt; text-align:center;
font-family:arial,sans-serif}
.menu {color:#FFCD6A; font-size:10pt; text-align:center;
font-family:arial,sans-serif; font-weight:bold}
td {background:black}
p {color:white; font-size:12pt; text-align:justify;
font-family:arial,sans-serif}
p.foot {color:white; font-size:9pt; text-align:center;
font-family:arial,sans-serif; font-weight:bold}
a:link,a:visited,a:active {color:white}
</style>
<?
}

function MostrarCabecera()
{
?>
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<th scope="col"><div align="center">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="780" height="237">
<param name="movie" value="0042.swf">
<param name="quality" value="high">
<embed src="0042.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="237"></embed>
</object>
</div></th>
</tr>
</table>
<?
}

function MostrarMenu($botones)
{
echo "<table width = \"100%\" bgcolor = white cellpadding = 4 cellspacing = 4>\n";
echo " <tr>\n";

//calcular tamaño botones
$width = 100/count($botones);

while (list($nombre, $url) = each($botones))
{
$this -> MostrarBoton($width, $nombre, $url, !$this->IsURLCurrentPage($url));
}
echo " </tr>\n";
echo "</table>\n";
}

function IsURLCurrentPage($url)
{
if(strpos( $GLOBALS["SCRIPT_NAME"], $url )==false)
{
return false;
}
else
{
return true;
}
}

function MostrarBoton($width, $nombre, $url, $activo = true)
{
if ($activo)
{
echo "<td width = \"$width%\">
<a href = \"$url\">
<img src = \"s-logo.gif\" alt = \"$nombre\" border = 0></a>
<a href = \"$url\"><span class=menu>$nombre</span></a></td>";
}
else
{
echo "<td width = \"$width%\">
<img src = \"side-logo.gif\">
<span class=menu>$nombre</span></td>";
}
}

function MostrarFooter()
{
?>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (footer.psd) -->
<table id="Tabla_01" width="100%" height="51" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="Images/12.jpg" width="234" height="22" alt=""></td>
<td>
<img src="Images/13.jpg" width="65" height="22" alt=""></td>
<td>
<img src="Images/14.jpg" width="54" height="22" alt=""></td>
<td>
<img src="Images/15.jpg" width="58" height="22" alt=""></td>
<td>
<img src="Images/16.jpg" width="64" height="22" alt=""></td>
<td>
<img src="Images/17.jpg" width="67" height="22" alt=""></td>
<td>
<img src="Images/18.jpg" width="238" height="22" alt=""></td>
</tr>
<tr>
<td colspan="7">
<img src="Images/19.jpg" width="100%" height="29" alt=""></td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
<?
}
}
?>


He intentado lo que me has dicho de heredoc pero me da un error:

Parse error: syntax error, unexpected T_ECHO, expecting ')' in C:\AppServ\www\Practicas_Mias\practicas21\inicio.p hp on line 7


El código introducido ha sido:


<?php
require ("pagina.php");

$paginaInicio = new Pagina();

$paginaInicio -> SetContenidos
(echo <<<EOT
<!-- end content -->
<!-- start sidebars -->
<div id="sidebar2" class="sidebar">
<ul>
<li>
<form id="searchform" method="get" action="#">
<div>
<h2>Site Search</h2>
<input type="text" name="s" id="s" size="15" value="" />
</div>
</form>
</li>
<li>
<h2>Tags</h2>
<p class="tag"><a href="#">dolor</a> <a href="#">ipsum</a> <a href="#">lorem</a> <a href="#">sit amet</a> <a href="#">dolor</a> <a href="#">ipsum</a> <a href="#">lorem</a> <a href="#">sit amet</a></p></li>
<li>
<h2>Calendar</h2>
<div id="calendar_wrap">
<table summary="Calendar">
<caption>
October 2009
</caption>
<thead>
<tr>
<th abbr="Monday" scope="col" title="Monday">M</th>
<th abbr="Tuesday" scope="col" title="Tuesday">T</th>
<th abbr="Wednesday" scope="col" title="Wednesday">W</th>
<th abbr="Thursday" scope="col" title="Thursday">T</th>
<th abbr="Friday" scope="col" title="Friday">F</th>
<th abbr="Saturday" scope="col" title="Saturday">S</th>
<th abbr="Sunday" scope="col" title="Sunday">S</th>
</tr>
</thead>
<tfoot>
<tr>
<td abbr="September" colspan="3" id="prev"><a href="#" title="View posts for September 2009">&laquo; Sep</a></td>
<td class="pad">&nbsp;</td>
<td colspan="3" id="next">&nbsp;</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td id="today">4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
<tr>
<td>29</td>
<td>30</td>
<td>31</td>
<td class="pad" colspan="4">&nbsp;</td>
</tr>
</tbody>
</table>
</div>
</li>
<li>
<h2>Categories</h2>
<ul>
<li><a href="#">Aliquam libero</a></li>
<li><a href="#">Consectetuer adipiscing elit</a></li>
<li><a href="#">Metus aliquam pellentesque</a></li>
<li><a href="#">Suspendisse iaculis mauris</a></li>
<li><a href="#">Urnanet non molestie semper</a></li>
<li><a href="#">Proin gravida orci porttitor</a></li>
<li><a href="#">Aliquam libero</a></li>
<li><a href="#">Consectetuer adipiscing elit</a></li>
<li><a href="#">Metus aliquam pellentesque</a></li>
<li><a href="#">Urnanet non molestie semper</a></li>
<li><a href="#">Proin gravida orci porttitor</a></li>
<li><a href="#">Aliquam libero</a></li>
<li><a href="#">Consectetuer adipiscing elit</a></li>
<li><a href="#">Metus aliquam pellentesque</a></li>
<li><a href="#">Suspendisse iaculis mauris</a></li>
<li><a href="#">Urnanet non molestie semper</a></li>
<li><a href="#">Proin gravida orci porttitor</a></li>
<li><a href="#">Metus aliquam pellentesque</a></li>
<li><a href="#">Suspendisse iaculis mauris</a></li>
<li><a href="#">Urnanet non molestie semper</a></li>
<li><a href="#">Proin gravida orci porttitor</a></li>
<li><a href="#">Metus aliquam pellentesque</a></li>
</ul>
</li>
</ul>
</div>
<!-- end sidebars -->





EOT;);
$paginaInicio -> Mostrar();
?>
  #2 (permalink)  
Antiguo 24/08/2010, 17:17
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 8 meses
Puntos: 1532
Respuesta: heredoc

no repitas el tema!!!!, ya te respondi: http://www.forosdelweb.com/f91/codig...1/#post3531700
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 02:22.