PDA

View Full Version : Simple mark-up for CMS


gsoper
02-13-2004, 02:08 PM
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

bcarl314
02-13-2004, 02:23 PM
I just posted something on this, see this thread: http://www.codingforums.com/showthread.php?s=&threadid=33268

The ubbc.php is a script that allows you to use ubb code. Like the [url] and stuff.

Celtboy
02-13-2004, 08:59 PM
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:


$markup = array("
0=>",",
1=>",",
);

kinda thing...if memory serves. not nearly as many lines of code.

Celtboy
02-13-2004, 10:50 PM
function process_comment($comment_text) {
$finds = array();
$replaces = array();

$comment_text = htmlspecialchars($comment_text);
$bbcode = array (
"" => "<strong>",
"" => "</strong>",
"" => "<em>",
"" => "</em>"
);

$comment_text = str_replace( array_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;
}