note 25515 deleted from function.preg-replace by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 12:31:33 +0000 |
| Subject: | note 25515 deleted from function.preg-replace by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57476@lists.php.net to get a copy of this message | ||
Note Submitter: dkg@con-fuse.org
----
this is a parser for parsing html code in a textarea:
<?
function unhtmlentities ($string) {
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
return strtr ($string, $trans_tbl);
}
function parsehtml ($txt) {
if($txt) {
$txt = htmlentities($txt);
$txt = str_replace(array('<!--', '-->'),
array('<!--', '-->'), $txt);
$txt = preg_replace ("/(?=<!--html_start-->)|
((?<=<!--html_start-->)
((?:.|\r|\n)*)(?=<!--html_end-->))|
(?<=<!--html_end-->)/eiU","unhtmlentities('\\1')", $txt);
$txt = str_replace("\n", "<br>", $txt);
$txt = str_replace('\\"', "\"", $txt);
$txt = str_replace("\\'", "'", $txt);
}
return $txt;
}
$txt = parsehtml($txt);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<meta name="generator" content="HTML
Tidy for Linux/x86 (vers 1st March 2002), see www.w3.org">
<title>HTML / Plain-Text Parser</title>
</head>
<body>
<form method="post" action="<?=$PHP_SELF;?>">
<?
if($txt) {
$txt_out = str_replace("<br>", "\n", $txt);
?>
<textarea name="txt" rows=30
cols=50><?=$txt_out?></textarea>
<? } else { ?>
<textarea name="txt" rows=30 cols=50></textarea>
<? } ?>
<input type="submit" value="send">
</form>
<? if($txt) { echo $txt; } ?>
</body>
</html>