Translate PHP String Functions to Javascript / jQuery
This is the PHP code I'm trying to translate into Javascript / jQuery. Any ideas?
$root_folder = 'es';
$url = "http://domainNamehere.com/event/test-event-in-the-future/";
开发者_如何学JAVA
$p = strpos($url, '/', 8);
$url_new = sprintf('%s/%s/%s', substr($url, 0, $p), $root_folder, substr($url, $p+1));
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 + "/");
strpos() ~ .indexOf()
substr() ~ .substring()
sprintf() ~ +
PHP.js offers ports of many common PHP functions to JavaScript.
精彩评论