PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_BBCodeParser » Bug #2575

HTML to UBB method

Details

Request #2575HTML to UBB method
Submitted2004-10-20 13:54 UTC
Fromignatius dot reilly at free dot fr
StatusWont fix
PackageHTML_BBCodeParser
PHP VersionIrrelevant
OSirrelevant
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;
}