Character normalization

Hi.

I’d like to normalize in a string the characters below. To no effect so far.


    //character normalization
    $text = str_replace("’","'",$text);
    $text = str_replace("“",'"',$text);
    $text = str_replace("”",'"',$text);
    $text = str_replace("’","'",$text);
    
    echo('<pre>');
    print_r($text);
    echo('</pre>');
    die();

Once echoed, $text doesn’t reflect a single change compared to original string.

How would you do that? Am I missing an obvious point?

:slight_smile:

If you are stripping Ms Word style quotes take a look at this user contributed note PHP: str_replace - Manual

Your $text code might be accepting utf-8 strings or char encoded strings, its not clear from what you have posted.

Thanks for your reply.

Therein lies the problem, I guess. I’m still very confused when it comes to char encoding. Should my $text be utf-8 or not (mb_detect_encoding() says it is)? Is the function you posted to dealing with utf-8 strings or not?

For the sake of resolving the problem faster, I shall add that $est is the result of a $_POST variable.

:slight_smile: