I'm writing a script to translate "bbCode". Here's the relevant segment.
// Url's and email's
$text = eregi_replace("[url=([][ ])]([[])[/url]", "<a href=\"\1\">\2</a>", $text);
// Must be first b/c of url parsing
$text = eregi_replace("([a-z]+://[^ \n\r\t])", "<a href=\"\1\">\1</a>", $text);
$text = eregi_replace("[email]([[ ])[/email]", "<a href=\"mailto:\1\">\1</a>", $text);
You'll notice the comment about one for xxx needing to be first. Otherwise the one that just parses xxx://xxx picks up the url and messes it up. However, even now that I've put it first, it still acts as though the xxx://xxx one got it first. I input this:
haha
..and it gives me this:
[url=<a href="http://foo.com]haha[/url]">http://foo.com]haha[/url]</a>
Any help is greatly appreciated.