EDITED/FIXED
- Added
str_replace() to deal with dots in domain names
- Initially I fixed your backslashes (if you want a literal backslash in your Regex it should be
\\ in the string) but I have undone this as you have said it was working for you in the first place.
How about this?
$mydomain = 'domain.tld';
$bbcode = array (
"/\[url\=([^]]*)(".str_replace('.','\\.',$mydomain).")([^]]*)\]([^[]*)\[\/url\]/is" => "<a href='$1$2$3' target='top'>$4</a>",
"/\[url\]([^[]*)(".str_replace('.','\\.',$mydomain).")([^[]*)\[\/url\]/is" => "<a href='$1$2$3' target='top'>$1$2$3</a>";
"/\[url\=([^]]*)\]([^[]*)\[\/url]/is" => "<a href='$1' target='_blank'>$2</a>"
"/\[url\]([^[]*)\[\/url\]/is" => "<a href='$1' target='_blank'>$1</a>",
);
If that will work for you, a caveat: Don't set $mydomain to www.domain.tld, set it to domain.tld, so you catch all subdomains.
You could even do it with multiple domains like this:
$mydomains = array(
'domain.tld',
'anotherdomain.tld',
'sub.yetanotherdomain.tld'
);
// Add domain-specific rules before general rules so we don't match domain
// specific links with the general link rule (we have replaced them by that point)
$domainrules = array();
foreach ($mydomains as $domain) {
$domainrules["/\[url\=([^]]*)(".str_replace('.','\\.',$domain).")([^]]*)\]([^[]*)\[\/url\]/is"] = "<a href='$1$2$3' target='top'>$4</a>";
$domainrules["/\[url\]([^[]*)(".str_replace('.','\\.',$domain).")([^[]*)\[\/url\]/is"] = "<a href='$1$2$3' target='top'>$1$2$3</a>";
}
// This array contains all your static BBCode rules
$staticrules = array(
"/\[url\=([^]]*)\]([^[]*)\[\/url\]/is" => "<a href='$1' target='_blank'>$2</a>",
"/\[url\]([^[]*)\[\/url\]/is" => "<a href='$1' target='_blank'>$1</a>",
"/\[b\]([^[]*)\[\/b\]/is" => "<span class='bold_text'>$1</span>",
...
);
// Make an array that contains all the rules
$bbcode = array_merge($staticrules,$domainrules);