-function enriched_to_text($input,$html=false,$just=false,$indent=0,$width=68)
-{
- $text = trim($input);
- if ($html) {
- $text = htmlspecialchars($text);
- $text = str_replace('[b]','<strong>', $text);
- $text = str_replace('[/b]','</strong>', $text);
- $text = str_replace('[i]','<em>', $text);
- $text = str_replace('[/i]','</em>', $text);
- $text = str_replace('[u]','<span style="text-decoration: underline">', $text);
- $text = str_replace('[/u]','</span>', $text);
- $text = preg_replace('!((https?|ftp)://[^\r\n\t ]*)!','<a href="\1">\1</a>', $text);
- $text = preg_replace('!(([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)(?:\?[^\r\n\t ]*)?)!','<a href="mailto:\1">\2</a>', $text);
- return nl2br($text);
- } else {
- $text = preg_replace('!\[\/?b\]!','*',$text);
- $text = preg_replace('!\[\/?u\]!','_',$text);
- $text = preg_replace('!\[\/?i\]!','/',$text);
- $text = preg_replace('!((https?|ftp)://[^\r\n\t ]*)!','[\1]', $text);
- $text = preg_replace('!(([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)(?:\?[^\r\n\t ]*)?)!','[mailto:\1]', $text);
- $text = $just ? justify($text,$width-$indent) : wordwrap($text,$width-$indent);
- if($indent) {
- $ind = str_pad('',$indent);
- $text = $ind.str_replace("\n","\n$ind",$text);
- }
- return $text;