Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.2.4

Request #2575 HTML to UBB method
Submitted: 2004-10-20 13:54 UTC
From: ignatius dot reilly at free dot fr Assigned:
Status: Wont fix Package: HTML_BBCodeParser
PHP Version: Irrelevant OS: irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [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; }

Comments

 [2005-06-08 10:40 UTC] nagash
Well it isn't quite that easy :) Have to take into account attributes...
 [2007-06-04 21:15 UTC] dufuz (Helgi Þormar)
Use the text_wiki package, it has exactly that purpose.