0

How can I do this in 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);
user1087110
  • 3,633
  • 11
  • 34
  • 43

2 Answers2

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

See here for details: http://www.w3schools.com/jsref/jsref_obj_string.asp

Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
0

Mozilla has an amazing reference readily available to you. I've included some link in my response below.

Have a look at toLocaleLowerCase for lower casing your string. Then move on to replace which is really in many ways very similar to preg_replace in that it is primarily based on regular expressions.

Lots of reading, but it shouldn't be too hard! Good luck!

Leonard
  • 3,012
  • 2
  • 31
  • 52