Skip navigation.
Home

archives

Generating nice HTML with PHP... forget the PHP.

Bad Architecture

Jumping in and out of HTML in PHP is a fundamental part of the language but what if you didn't know that? What if you wanted PHP to generate some nicely formatted HTML? Props to Thiemo Mättig for sending in this WTF.

This is probably the most 'clever' way of adding in tabs and new lines to format HTML.

<?php
$n
= chr(13);
$t = chr(9);
$nt = $n.$t;
$ntt = $n.$t.$t;
$nttt = $n.$t.$t.$t;
$ntttt = $n.$t.$t.$t.$t;
$nttttt = $n.$t.$t.$t.$t.$t;
?>

and a little furthur...

<?php
$html
.= $nttt.'<table>';
$html .= $ntttt.'<tr>';
$html .= $nttttt.'<th>...</th>';
$html .= $nttttt.'<th>...</th>';
$html .= $ntttt.'</tr>';
$html .= $ntttt.'<tr>';
$html .= $nttttt.'<td>...</td>';
$html .= $nttttt.'<td>...</td>';
$html .= $ntttt.'</tr>';
$html .= $nttt.'</table>';
?>