如何在javascript中执行“strtolower”,“str_replace”和“preg_replace”?

时间:2012-07-31 11:25:50

标签: javascript

我怎样才能在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);

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

Mozilla有一个很棒的参考资料。我在下面的回复中提供了一些链接。

请查看toLocaleLowerCase以获得较低的字符串。然后转到replace,这在很多方面与preg_replace非常相似,因为它主要基于正则表达式。

很多阅读,但它不应该太难!祝你好运!