|
Posted by Pedro Graca on 10/19/06 19:17
ChianHsieh@gmail.com wrote:
> Example:
>
> Before Filter:
> <div id="pp"> hello man <br/> Thank's for your answer. </div>
>
> After Filter:
> <div id="pp"> <br/> </div>
I lova good challenges :)
<?php
function get_html($x, $sep=' ') {
$inbrackets = false;
$inquotes = false;
$html = '';
$l = strlen($x);
for ($i = 0; $i < $l; ++$i) {
$y = substr($x, $i, 1);
if (($inbrackets) && ($y == '"')) {
$inquotes = !$inquotes;
}
if ((!$inquotes) && ($y == '<')) {
if ($i > 0) {
$html .= $sep;
}
$inbrackets = true;
}
if ($inbrackets) {
$html .= $y;
}
if ((!$inquotes) && ($y == '>')) {
$inbrackets = false;
}
}
return $html;
}
$data = <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title>example</title></head>
<body>
<div id="pp">
<a name="funky><name"></a>
<!-- *VALID*^^*HTML* -->
hello man<br/>
Thank's for your answer.
</div>
</body>
</html>
HTML;
$html = get_html($data, "\n");
echo $html;
?>
Or you could try a regular expression (but I'm not sure you could do one
that accepts all valid HTML).
--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Navigation:
[Reply to this message]
|