PHP ver gevorderde |
|
Ik gebruik hier zelf het volgende voor:
Functies:
<?php
function startCompressing()
{
ob_start();
}
function stopCompressing()
{
$sSource = ob_get_contents();
ob_end_clean();
$bBefore = false;
$aSource = explode("\n", str_replace("\r", '', $sSource));
foreach($aSource as $i => $sLine)
{
$sLine = trim($sLine);
if(empty($sLine))
{
unset($aSource[$i]);
}
else
{
$aSource[$i] = $sLine;
$bCurrent = ($sLine{0} != '<') ? true : false;
if(!($bCurrent == $bBefore && $bCurrent === false))
{
$aSource[$i] = ' '.$sLine;
}
$bBefore = ($sLine{strlen($sLine) - 1} != '>') ? true : false;
}
}
echo implode('', $aSource);
}
?>
<?php function startCompressing() { } function stopCompressing() { $bBefore = false; foreach($aSource as $i => $sLine) { { } else { $aSource[$i] = $sLine; $bCurrent = ($sLine{0} != '<') ? true : false; if(!($bCurrent == $bBefore && $bCurrent === false)) { $aSource[$i] = ' '.$sLine; } $bBefore = ($sLine{strlen($sLine) - 1} != '>') ? true : false; } } } ?>
gebruik:
<?php
startCompressing();
?>
<div>
<img src="..." alt="..." />
</div>
<?php
stopCompressing();
?>
<?php startCompressing(); ?> <div> <img src="..." alt="..." /> </div> <?php stopCompressing(); ?>
|