Home » HTML » HTML_BBCodeParser » Bug #2575
HTML to UBB method
Details
| Request #2575 | HTML to UBB method |
|---|---|
| Submitted | 2004-10-20 13:54 UTC |
| From | ignatius dot reilly at free dot fr |
| Status | Wont fix |
| Package | HTML_BBCodeParser |
| PHP Version | Irrelevant |
| OS | irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2004-10-20 13:54 UTC] ignatius dot reilly at free dot fr
Description:
------------
It would be nice to have a "reverse" static method in the same package, to replace HTML with UBB tags
So that one can easily manage a textarea in a form in "edit" mode.
Although simple to write, it would be convenient to have it in the same package.
Reproduce code:
---------------
Something along these lines:
// Loosely adapted from: http://www.phpclasses.org/browse.html/package/818.html
function decode($str) {
$str = eregi_replace("(<b>|<strong>)", '[b]', $str);
$str = eregi_replace("(</b>|</strong>)", '[/b]', $str);
$str = eregi_replace("(<i>|<em>)", '[i]', $str);
$str = eregi_replace("(</i>|</em>)", '[/i]', $str);
$str = eregi_replace("\<u\>", '[u]', $str);
$str = eregi_replace("\</u\>", '[/u]', $str);
$str = eregi_replace("\<center\>", '[center]', $str);
$str = eregi_replace("\</center\>", '[/center]', $str);
$str = eregi_replace("\<code\>", '[pre]', $str);
$str = eregi_replace("\</code\>", '[/pre]', $str);
$str = eregi_replace("\\<font color=([^>\[]*)\\>([^<\[]*)</font>" ,"[color=\"\\1\"]\\2[/color]",$str);
$str = eregi_replace("\\<a href=\"([^\\[\"]*)\"\\ target=\"_blank\">([^<\[]*)</a>","[url=\\1]\\2[/url]", $str);
$str = eregi_replace("\\<a href=\"mailto:([^\\[]*)\"\\>([^<\[]*)</a>","[email=\\1]\\2[/email]",$str);
$str = eregi_replace("\\<img src=\"([^\\[]*)\"\\ border=0>([^<\[]*)","[img]\\1[/img]",$str);
$str = eregi_replace("\<blockquote><smallfont>Quote:</smallfont><hr>", '[quote]', $str);
$str = eregi_replace("\<hr></blockquote>", '[/quote]', $str);
$str = eregi_replace("\<hr></blockquote>", '[/quote]', $str);
$str = eregi_replace("\<br />\n", '/n', $str);
$str = eregi_replace("\<br>", '/n', $str);
$str = eregi_replace("<ul>(.*)</ul>","[ulist]\\1[/ulist]",$str);
$str = eregi_replace("<ol>(.*)</ol>","[list]\\1[/list]",$str);
$str = eregi_replace( "<li>([^<]*)</li>","[*]\\1",$str ) ;
return $str;
}