note 25515 added to function.preg-replace
| From: | dkg at con-fuse dot org | Date: | Thu, 26 Sep 2002 11:41:35 +0000 |
| Subject: | note 25515 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37277@lists.php.net to get a copy of this message | ||
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>
--
http://www.php.net/manual/en/function.preg-replace.php
http://master.php.net/manage/user-notes.php?action=edit+25515
http://master.php.net/manage/user-notes.php?action=delete+25515
http://master.php.net/manage/user-notes.php?action=reject+25515