开发者

Translate PHP String Functions to Javascript / jQuery

开发者 https://www.devze.com 2023-04-10 13:13 出处:网络
This is the PHP code I\'m trying to translate into Javascript / jQuery.Any ideas? $root_folder = \'es\';

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

精彩评论

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