I am trying to build a function in php that will take the input of a string and encode it correctly before displaying it. So far I have:
public function encode($str)
{
if(!preg_match('!!u', $str)) // Needs to be encoded
{
$str = "YES: " . $str;
$str = utf8_encode($str);
}
else
{
$str = "NO: " . $str;
}
return $str;
}
The if statement I am using i found here. And it works in some cases but in others it is encoding the string when they shouldn't be.
Perhaps there is an easier way to handle the encoding ?