我怎样才能在javascript中做到这一点?
$name = $xml->name;
$file_name = strtolower($name);
$file_name = str_replace(array('-',' ',' ','å','ä','ö'), array('',' ','-','a','a','o'), $file_name);
$file_name = preg_replace("/[^a-z0-9-]+/i", "", $file_name);
我怎样才能在javascript中做到这一点?
$name = $xml->name;
$file_name = strtolower($name);
$file_name = str_replace(array('-',' ',' ','å','ä','ö'), array('',' ','-','a','a','o'), $file_name);
$file_name = preg_replace("/[^a-z0-9-]+/i", "", $file_name);
toLowerCase() Converts a string to lowercase letters
toUpperCase() Converts a string to uppercase letters
replace() Searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring
search() Searches for a match between a regular expression and a string, and returns the position of the match
有关详细信息,请参见此处:http: //www.w3schools.com/jsref/jsref_obj_string.asp
Mozilla 为您提供了一个很棒的参考资料。我在下面的回复中包含了一些链接。
查看toLocaleLowerCase以降低您的字符串的大小写。然后继续替换它在许多方面实际上非常相似preg_replace
,因为它主要基于正则表达式。
阅读量很大,但不应该太难!祝你好运!