开发者

how to do str_replace on everything that is returned with get_defined_vars? (php)

how do i do a str_replace on everything that is returned in get_defined_vars? doing it with normal strings is easy, b开发者_开发技巧ut what about objects/classes?


This sounds like a bad idea, so I'll just answer the actual problem of hardcoded domains. Fix this problem directly instead of applying more bandaid on top of a bad structure.

You should replace every occurrence of a hardcoded domain with a constant (using your text editors search/replace, not PHP), that you can switch however you like.

if (/* something */) {
    define('MYAPP_BASE_URL', 'http://example.com');
} else {
    define('MYAPP_BASE_URL', 'http://example2.com');
}

…

$url = MYAPP_BASE_URL;

Better yet, your code should be dynamic enough to be using $_SERVER['HTTP_HOST'] to begin with.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜