How to Convert HTML Link Code into BBCode With PHP

By | September 26, 2008

Another short function appears on my blog. If you need to convert your HTML code, containing links only, into BBcode, you need this function:

function make_bbcode($normal)
{
$samurl=str_replace(“<a href=”, “[url=”, $normal);
$samurl=str_replace(“</a>”, “[/url]”, $samurl);
$samurl=str_replace(“>”, “]”, $samurl);
return($samurl);
}

That’s a very simple solution that doesn’t cover all the instances of HTML code. If you need a good converter, I’d suggest you this one. That’s a great service that allows you to deal with different options of forum code, and it’s absolutely free. You’re also welcome to download and run HTML to BBCode converter script . Source code is available there so you can organize your own service of code conversion :) Another simple service that has any design is this one. I don’t think there is any difference as the script is quite simple and free.