这是我试图翻译成 Javascript/jQuery 的 PHP 代码。有任何想法吗?
$root_folder = 'es';
$url = "http://domainNamehere.com/event/test-event-in-the-future/";
$p = strpos($url, '/', 8);
$url_new = sprintf('%s/%s/%s', substr($url, 0, $p), $root_folder, substr($url, $p+1));
strpos() ~ .indexOf()
substr() ~ .substring()
sprintf() ~ +
var root_folder = "es",
url = "http://domainNamehere.com/event/test-event-in-the-future/",
url_new = "",
path_finder = /^(((http)s?:)?\/\/[^\/]+\/)/i;
url_new = url.replace(path_finder, "$1" + root_folder + "/");
PHP.js为 JavaScript 提供了许多常见 PHP 函数的端口。