What PHP-based plain text formatting processor do you recommend?
* hello * -> hello
_ hello _ -> hello
.etc (without the spaces)
Observing members:
0
Composing members:
0
3 Answers
I usually just write my own.
Two arrays, str_replace or preg_replace, and you’re done (unless you want to add some extra safety measures).
For example, for your two examples, I’d do this:
$search = array(’/\*(.*?)\*/is’, ’/\_(.*?)\_/is’);
$replace = array(’<em>$1</em>’, ’<strong>$1</strong>’);
$string = preg_replace($search, $replace, $string);
I prefer just allowing HTML (though securing it using HTML Purifier, an excellent yet underused tool) and perhaps add WYMeditor for easy markup. However, Wikipedia knows quite a few and I suppose most of them also have PHP ports or are PHP native, such as TextilePHP.
Thanks both for your answers. I was considering using Textile, but it’s too bloated for what I need it for really (although very good), and lefteh’s suggestion is the road I was going down if I didn’t find anything. I guess I’ll be writing my own then.
Cheers again!
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.