Jump to content

special chars - url


Rommeo

Recommended Posts

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 ?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.