Web Analytics Made Easy -
StatCounter Simple mark-up for CMS - CodingForum

Announcement

Collapse
No announcement yet.

Simple mark-up for CMS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple mark-up for CMS

    I'm designing/coding a content management system in PHP and am currently considering how the users will add textual content. I would like them to be able to use some kind of simple mark-up, like a very limited subset of HTML, probably with a more friendly naming scheme. Does anybody have experience of such a thing? I'm thinking an XML application is the proper answer but when I consider the DTD and parser it seems like an overkill solution if I'm starting from scratch.
    Does anybody have any advice or suggestions on this? I'm sure it's been done before but I don't know where to look, is there something existing I can use or adapt? Has anybody tried this kind of thing before?

    I'd really appreciate any kind of help in this,
    Geoff

  • #2
    I just posted something on this, see this thread: http://www.codingforum.net/showthrea...threadid=33268

    The ubbc.php is a script that allows you to use ubb code. Like the [url] and stuff.
    Create accessible online surveys -::- Koobten.com - compare netbook prices and reviews -::- Affordable, reliable hosting for less than $20 per year
    Zend Certified Engineer

    Comment


    • #3
      the best way that I've found is to write a function (I have one at home, currently at work), that accepts a string (the user's text).

      Using regular expressions, it runs through an array, replacing the custom markup, and returning the parsed text. I'll be glad to post the code for you when i get home.


      I've used it to add custom conditional statements to templates..very handy...


      -Celt


      ps...it kinda looks like that code bcarl posted, but much cleaner. It simply uses an array like:

      PHP Code:
      $markup = array("
      0=>"
      [image],[/image]",
      1=>"
      [url],[/url]",
      ); 
      kinda thing...if memory serves. not nearly as many lines of code.
      Last edited by Celtboy; Feb 13, 2004, 05:11 PM.

      Comment


      • #4
        PHP Code:
        function process_comment($comment_text) {
            
        $finds = array();
                
        $replaces = array();
                
                
        $comment_text htmlspecialchars($comment_text);        
                
        $bbcode = array (    
                    
        "[b]" => "<strong>",    
                    
        "[/b]" => "</strong>",    
                    
        "[i]" => "<em>",    
                    
        "[/i]" => "</em>"    
                    
        );        
                
                
        $comment_text str_replacearray_keys($bbcode), $bbcode$comment_text );
                
        $finds[] = "/\[url=(.*?)\](.*)\[\/url\]/is";
                
        $replaces[] = '<a href="$1">$2</a>';
                
        $finds[] = '/(\A|\s)((http|ftp)+(s)?:-(\\/\\/)((\\w|\\.)+)(\\/)?(\\S+)?)(\Z|\s)/i';
                
        $replaces[] = ' <a href="$1">$6</a> ';
                
        $comment_text preg_replace($finds$replaces$comment_text);
                
        $comment_text nl2br($comment_text);
                
                return 
        $comment_text;

        Comment

        Working...
        X