Welcome Guest, Not a member yet? Register   Sign In
Character conversion to...?
#1

[eluser]IanMcQ[/eluser]
I have this function as a plugin:

Code:
function wordchar($str)
{
    return (strspn($str, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-') == strlen($str));
}

I use it to check if a string is an alphanumerical word character. However, characters such as ä, Ç, ö, ü, etc are getting past this function. In other words, if $a contains "ö", this function will still return TRUE despite ö's being prohibited!

My question is this: what does CodeIgniter convert characters to (I am using $this->input->post() to get the value of the string I'm checking)? My guess is that characters like ö are being translated into something different. How can I make it so these characters (like ö) don't get past this function?

ALSO -- ö's (among the others) pass through a similar preg function without detection.

Thanks.
#2

[eluser]Damien K.[/eluser]
I don't think this is CI-dependent although there may be internationalization settings (ie, locale/character encodings) you can set in CI. I think the web server and the box it's installed on affects the way internationalization is handled. Your test should not return TRUE.

You can try: mb_strlen($str) === strlen($str)
This may be a suitable "lazy" way to test for international characters as they occupy 2 bytes in UTF-8.




Theme © iAndrew 2016 - Forum software by © MyBB