Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
echo preg_replace(array(
'~\[b\](\w+)\[/b\]~',
'~\[i\](\w+)\[/i\]~i',
'~\[u\](\w+)\[/u\]~i',
'~\[s\](\w+)\[/s\]~i',
'~\[img\](\w+)\[/img\]~i',
'~\[url=(\w+)\](\w+)\[/url\]~i',
'~\[email\](\w+)\[/email\]~i',
'~\[quote=(\w+)\](\w+)\[/quote\]~i',
), array(
'<strong>$1</strong>',
'<em>$1</em>',
'$1',
'<del>$1</del>',
'<img src="$1" alt="">',
'<a rel="nofollow" href="$1">$2</a>',
'<a href="mailto:$1">$1</a>',
'<blockquote><p><strong>$1</strong> napsal(a):</p><p>$2</p></blockquote>',
),
'[b]tučné[/b]
[i]kurzíva[/i]
[u]bývalé podtržené (nyní bez tagů)[/u]
[s]přeškrtnuté[/s]
[img]http://obrazek[/img]
[url=http://test]test[/url]
[email]test@test.cz[/email]
[quote=Test]text[/quote]'
);
/* výsledek:
[b]tučné[/b]
[i]kurzíva[/i]
[u]bývalé podtržené (nyní bez tagů)[/u]
[s]přeškrtnuté[/s]
[img]http://obrazek[/img]
[url=http://test]test[/url]
[email]test@test.cz[/email]
<blockquote><p><strong>Test</strong> napsal(a):</p><p>text</p></blockquote> */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment