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

código html dentro del código php

Estas en el tema de código html dentro del código php en el foro de Diseño web en Foros del Web. He creado Pagina.inc y a partir de las clases y funciones en este archivo pretendo ir creando todas las páginas necesarias para el sitio Web, ...
  #1 (permalink)  
Antiguo 24/08/2010, 15:58
 
Fecha de Ingreso: agosto-2010
Mensajes: 4
Antigüedad: 13 años, 7 meses
Puntos: 0
Busqueda código html dentro del código php

He creado Pagina.inc y a partir de las clases y funciones en este archivo pretendo ir creando todas las páginas necesarias para el sitio Web, utilizando require y herencias:

En la primera página 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>
<?
}
}
?>
  #2 (permalink)  
Antiguo 24/08/2010, 16:05
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: código html dentro del código php

puedes usar heredoc: http://www.ignside.net/man/php/heredoc.php

NOTA: usa <?php en vez de <? debido a que los short_tag serán descartados en versiones futuras de php

la próxima vez que tengas una pregunta relacionada con php, postea en el foro de php directamente, así como con js, css, html, etc.
Código PHP:
Ver original
  1. //en el foro, para comodidad de lectura, puedes implementar los highlights
  2. //se encuantran en una lista desplegable en el editor de texto y tienes varias opciones
  #3 (permalink)  
Antiguo 24/08/2010, 16:15
 
Fecha de Ingreso: agosto-2010
Mensajes: 4
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: código html dentro del código php

Muchas gracias por tu respuesta, lo mandaré al foro de php, soy nuevo aquí y no había visto ese foro.

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();
?>
  #4 (permalink)  
Antiguo 24/08/2010, 17:16
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: código html dentro del código php

no puedes incluir heredoc de esa forma, no debe tener otros caracteres ni tabuladores ni cometarios excepto echo o alguna variable, lo mejor es recurrir a una variable
Código PHP:
$str = <<<EOT
todo tu codigo
EOT;
//luego llamas a tu función con la variable:
$paginaInicio -> SetContenidos($str); 
si te fijas el hightlight php me reconoce el heredoc colocandolo en color verde, puedes recurrir a notepad++, netbeans 6.9 o un IDE similar que maneje php para verificar a simple vista el heredoc bien implementado

y por favor no repitas el tema: http://www.forosdelweb.com/f91/heredoc-836319/

Etiquetas: html, php
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 18:33.