How to completely replace all special characters in PHP without leaving any HTML objects as a result

I need help with the PHP replacement function I'm trying to create.

Basically, I want FYLLY to convert all special characters, such as á, é, í, ó, ú, ü, ñ, Á, É, Í, Ó, Ú, Ü, Ñetc a, e, i, o, u, u, n, A, E, I, O, U, U, N. : . The following explains why I say "FULLY convert."

Now I managed to do it only half using the following function:

function clean_url($text){
         $text = preg_replace('~&([a-z]{1,10})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($text, ENT_QUOTES, 'UTF-8'));
    return $text;
}

This at first glance gives me the desired result when viewing in MySQL or in a browser, so in PHP:

$string = "Ábalos";
echo clean_url($string);

Output source code HTML-page Abalos. It looks right at first glance.

But when I do

$string = "Ábalos";
echo htmlentities(clean_url(($string));

Output source code HTML-page AÂ?balos.

I want my function to be able to replace this part as well Â?. How can this be achieved?

+4
2

( : "" ASCII?:

function toASCII( $str )
{
    return strtr(utf8_decode($str), 
        utf8_decode(
        'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'),
        'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy');
}

, . :

function toASCII( $str )
{
    return strtr(utf8_decode($str), 
        utf8_decode(
        'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'),
        'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy');
}

$string = "Ábalos";

echo toASCII($string);

Abalos

+2

iconv .

<?php

    setlocale(LC_ALL, 'en_US.UTF-8');

    $str = "Ábalos";

    echo iconv('UTF-8', 'ASCII//TRANSLIT', $str);

?>
+2

All Articles