/ Published in: PHP
URL: http://nothingconcept.com
This is a version of Textile that only accepts paragraps, bold, italics, links, and images. Enjoy.
Expand |
Embed | Plain Text
<?php class TextiLite{ /* TextiLite: A lightweight version of Textile built with PHP by Evan Walsh Version 001 Based on the work of: http://codeigniter.com/wiki/BBCode_Helper/ http://codeigniter.com/forums/viewthread/69615/ Supports: <br/> by the way of newline *Text* => <strong>Text</strong> _Text_ => <em>Text</em> !http://image.url! => <img src="http://image.url"/> "Text":http://text.url => <a href="http://text.url" title="Text">Text</a> */ function paragraph($text){ $output = null; foreach($paragraphs as $paragraph) { $output .= "\n<p>".$paragraph."</p>\n"; } return $output; } function textile($text = null){ '/(.+)\n(.+)/', '/\*([^\*]+)\*/', '/\_([^\*]+)\_/', '/(!)((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))(!)/', '/(")(.*?)(").*?((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))/', ); "$1<br/>$2", "<strong>$1</strong>", "<em>$1</em>", "<img src=\"$2\"/>", "<a href=\"$4\" title=\"$2\">$2</a>", ); } function process($text){ $text = $this->paragraph($text); $text = $this->textile($text); return $text; } } ?>
Comments
Subscribe to comments
You need to login to post a comment.

Thanks for this!
Thanks, I was looking for something like that. I see two minor problems though : -line 35 I'm pretty sure it should be [^_] instead of [^*] since you want any characters except underscores. -line 26 I don't think you need a \n in front of the first
, and it actually produces an extra at the beginning of your text when you use paragraph() then textile().