Etiquetas de PHP

Cuando PHP analiza un fichero, busca las etiquetas de apertura y cierre, que son <?php y ?>, y que indican a PHP dónde empezar y finalizar la interpretación del código. Este mecanismo permite embeber a PHP en todo tipo de documentos, ya que todo lo que esté fuera de las etiquetas de apertura y cierre de PHP será ignorado por el analizador.

PHP también permite la etiqueta de apertura abreviada <? (la cual está desaconsejada debido a que sólo está disponible si se habilita con la directiva short_open_tag del fichero de configuración php.ini, o si PHP se configuró con la opción --enable-short-tags).

Si un fichero contiene solamente código de PHP, es preferible omitir la etiqueta de cierre de PHP al final del mismo. Así se previene la adición de espacios en blanco o nuevas líneas accidentales después de la etiqueta de cierre, lo cual causaría efectos no deseados debido a que PHP comenzará la salida del búfer cuando no había intención por parte del programador de enviar ninguna salida en ese punto del script.

echo "Hola mundo";

// ... más código

echo "Última sentencia";

// el script finaliza aquí sin etiqueta de cierre de PHP

Historial de cambios
Versión Descripción
7.0.0 Se eliminaron de PHP las etiquetas de ASP <%, %>, <%=, y la etiqueta de script <script language="php">.
5.4.0 La etiqueta <?= siempre está disponible independientemente del ajuste ini short_open_tag.

add a note

User Contributed Notes 2 notes

Jake Paul
5 days ago
I made a severe and continuous lapse in my judgement, and I don’t expect to be forgiven. I’m simply here to apologize. What we came across that day in the woods was obviously unplanned. The reactions you saw on tape were raw; they were unfiltered. None of us knew how to react or how to feel. I should have never posted the video. I should have put the cameras down and stopped recording what we were going through. There's a lot of things I should have done differently but I didn't. And for that, from the bottom of my heart, I am sorry. I want to apologize to the internet. I want to apologize to anyone who has seen the video. I want to apologize to anyone who has been affected or touched by mental illness, or depression, or suicide. But most importantly I want to apologize to the victim and his family. For my fans who are defending my actions, please don't. I don’t deserve to be defended. The goal with my content is always to entertain; to push the boundaries, to be all-inclusive. In the world I live in, I share almost everything I do. The intent is never to be heartless, cruel, or malicious. Like I said I made a huge mistake. I don’t expect to be forgiven, I’m just here to apologize. I'm ashamed of myself. I’m disappointed in myself. And I promise to be better. I will be better. Thank you.
3 months ago
A whitespace or newline character must follow '<?php' and precede '?>'.
To Top