Why encoding doesn't work in function?

时间:2017-01-11 15:18:03

标签: php regex function encoding character-encoding

I have a function for clean an input (delete trim, special caractere and number) in specific file and an index who i call this function.

// In index.php
$input = format_input($_POST['name']);

// In inc/function.php
function format_input($input){
    $pattern = '/[^a-zA-ZÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ\-\'\s]/';
    $output = preg_replace($pattern, "", $input);
    $output = trim($output);
    $output = ucfirst(strtolower($output));
    return $output;
}

if i use this function in my index, the encoding is OK, but if i use a call to this in another file, i have black losange on my regex.

the file are in utf-8 both, i don't understand why doesn't work !

1 个答案:

答案 0 :(得分:0)

试试这个:

$output = ucfirst(mb_strtolower($output,'utf-8'));

而不是:

$output = ucfirst(strtolower($output));

http://php.net/manual/en/function.mb-strtolower.php

相关问题