开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜