JJohnsenDK Posted March 17, 2008 Share Posted March 17, 2008 Hey How do i change letters in a string. And not just one letter. For example this string "Småbørn". Here are to none english letters which i want to change to english letters so i get: "Smaborn". How do i do this? $name = "Småbørn"; $len = strlen($name); $returnName = ""; for($i=0;$i<$len;$i++){ $letter = substr($name, $i, 1); echo "d"; if(strpos($letter, "å")){ $returnName .= str_replace("å", "a", $letter); }elseif(strpos($letter, "ø")){ $returnName .= str_replace("ø", "o", $letter); }elseif(strpos($letter, "å")){ $returnName .= str_replace("å", "a", $letter); }else{ $returnName .= $letter; } } echo $returnName; but it sucks. It doesnt work. Any ideas? Quote Link to comment Share on other sites More sharing options...
lemmin Posted March 17, 2008 Share Posted March 17, 2008 You should probably use preg_replace(). http://us.php.net/manual/en/function.preg-replace.php Good luck! Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted March 18, 2008 Author Share Posted March 18, 2008 sry for late reply... preg_replace doesnt help me much here? how should this be better than str_replace? Quote Link to comment Share on other sites More sharing options...
berridgeab Posted March 18, 2008 Share Posted March 18, 2008 I don't understand why you have an IF statement and a WHILE loop within your code. If your just looking to replace them characters with English characters then why not just use the str_replace() on its own? i.e $name = "Småbørn"; $name = str_replace("å", "a", $name); $name = str_replace("ø", "o", $name); $name = str_replace("å", "a", $name); echo $name; This worked fine for me. Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted March 18, 2008 Author Share Posted March 18, 2008 also works for me... thanks alot mate! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.