Rommeo Posted April 16, 2011 Share Posted April 16, 2011 I have members from different countries who uses different languages, and I want to let my members to search by using url; for example mysite.com/phpuser - has no problem mysite.com/kölnn - problem : user becomes "k%F6lnn" and script can not find the user. What s the easyway to solve this ? htaccess ? a function ? anything else ? Quote Link to comment https://forums.phpfreaks.com/topic/233892-special-chars-url/ Share on other sites More sharing options...
analog Posted April 16, 2011 Share Posted April 16, 2011 It's being encoded for the URL. You can use urldecode to convert it back. Quote Link to comment https://forums.phpfreaks.com/topic/233892-special-chars-url/#findComment-1202315 Share on other sites More sharing options...
Rommeo Posted April 16, 2011 Author Share Posted April 16, 2011 I have tried it, it did not work. it still says user "k%F6lnn" could not found. Quote Link to comment https://forums.phpfreaks.com/topic/233892-special-chars-url/#findComment-1202319 Share on other sites More sharing options...
analog Posted April 16, 2011 Share Posted April 16, 2011 urldecode should be converting it back. Can you post the bit of code that is not working. Quote Link to comment https://forums.phpfreaks.com/topic/233892-special-chars-url/#findComment-1202321 Share on other sites More sharing options...
Rommeo Posted April 16, 2011 Author Share Posted April 16, 2011 mysite.com/index.php?word=köln enter echo urldecode($_GET['word']); echo $_GET['word']; output : k�ln k�ln Quote Link to comment https://forums.phpfreaks.com/topic/233892-special-chars-url/#findComment-1202386 Share on other sites More sharing options...
analog Posted April 16, 2011 Share Posted April 16, 2011 Is it outputting the question mark � or %F6? If its the question mark then it has been decoded (well looking at it it didn't need it) and it is most likely because you to correct charset. Try using this: <?php function to_utf8( $string ) { // From http://w3.org/International/questions/qa-forms-utf-8.html if ( preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$%xs', $string) ) { return $string; } else { return iconv( 'CP1252', 'UTF-8', $string); } } echo to_utf8($_GET['word']); ?> From http://php.net/manual/en/function.urldecode.php first comment. Quote Link to comment https://forums.phpfreaks.com/topic/233892-special-chars-url/#findComment-1202393 Share on other sites More sharing options...
Rommeo Posted April 16, 2011 Author Share Posted April 16, 2011 Yes That function has kinda solved my problem. But there is another thing now, when I enter mysite.com/try.php?word=şüra it gives me " þüra " what can cause it ? Quote Link to comment https://forums.phpfreaks.com/topic/233892-special-chars-url/#findComment-1202407 Share on other sites More sharing options...
analog Posted April 16, 2011 Share Posted April 16, 2011 Most likely it's the web browser (works in FF4, IE9 but not Opera). The only characters guaranteed to work in a URL are ASCII after that things can go strange. You would need to urlencode it before putting it in the URL either by using PHP or you can do it with a simple HTML form for people to enter and the browser will encode it. <?php echo '<a href="?word=' . urlencode('şüra') . '">şüra</a>'; ?> <form action="" method="get"> <input type="text" name="word" value="şüra" /> <input type="submit" value="Lookup user" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/233892-special-chars-url/#findComment-1202419 Share on other sites More sharing options...
Rommeo Posted April 16, 2011 Author Share Posted April 16, 2011 Thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/233892-special-chars-url/#findComment-1202430 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.