Remove accent in PHP (Ã)

Asked

Viewed 3,313 times

1

I have the following function:

function tirarAcentos($string){
    return preg_replace(array("/(á|à|ã|â|ä)/","/(Á|À|Ã|Â|Ä)/","/(é|è|ê|ë)/","/(É|È|Ê|Ë)/","/(í|ì|î|ï)/","/(Í|Ì|Î|Ï)/","/(ó|ò|õ|ô|ö)/","/(Ó|Ò|Õ|Ô|Ö)/","/(ú|ù|û|ü)/","/(Ú|Ù|Û|Ü)/","/(ñ)/","/(Ñ)/","/(Ç)/","/(ç)/","/(Ã)/"),explode(" ","a A e E i I o O u U n N C c A"),$string);
}

However, when trying to remove an accent from the "GPA - SUGAR LOAF GROUP" I can’t remove the A specifically, I’ve tried everything and I can’t remove it.

How can I remove?

Follows the application:

session_register("SESSION");
header("Cache-Control: no-cache");
include('Connect.php');
include('conf.php');
include('sec.php');

$v_conexao = new MySQL($vstr_usuario,$vstr_pass,$vstr_host,$vstr_db) or die ("Can't connect with the database");
$vint_conexao=$v_conexao->Get_Connection_ID();

$ssql = "SELECT nome FROM ang_cliente ORDER BY nome ASC";
$vint_result=$v_conexao->Open_Query($vint_conexao,$ssql);
while($v_a=$v_conexao->Fetch_Into($vint_result)){
    $nome_removido = tirarAcentos($v_a['nome']);
    echo "Nome Atual: ".$v_a['nome']."<br>";
    echo "Nome Atualizado: ".$nome_removido."<br>";
    echo "<hr>";
}
  • 4

    Look at this http://answall.com/a/33047/15089

  • I’ve tried that way @Inkeliz but it doesn’t work :(

  • 1

    It may be that the connection Encode is different from the file (php)

1 answer

2

Through function iconv():

$text = "GPA - GRUPO PÃO DE ACUCAR";

setlocale(LC_CTYPE, 'pt_BR'); // Defines para pt-br
echo iconv('UTF-8', 'ASCII//TRANSLIT', $text);

What will give:

GPA - GRUPO PAO DE ACUCAR

It works for all kinds of accents and if you want to know more about the function, just check here on PHP Manual - iconv()

  • The result is the same... I can’t remove the "Is"

  • This is strange, I tested the code again in this online PHP editor and it works!! Check here --> http://www.writephponline.com/

  • I have tested everything that was a function and none of them can remove the Ã, I have tried using str_replace as well, nor does it remove. Just the best, the smallest remove normally

  • @Andrébaill must be some problem with your PHP, because str_replace('Ã','A',$text); works, I just tested.. what version of PHP you use?

  • @Andrébaill You can print the $vint_result following this line $vint_result=$v_conexao->Open_Query($vint_conexao,$ssql); and show what comes?

  • PHP Version 5.2.17

  • 1

    And it may be like @rray said above, Meeting may be different

  • if using var_dump() gives this result: Resource(4) of type (mysql result)

  • And what framework are you working with? It’s just that it might be in Ncode differently and then it doesn’t work as it should :s I’m not familiar with how you link to BD, so I don’t know if it will or not :s

  • (In this case, I am not using any framework). This system is old, in PHP version 5.2, if I change the function, it will not work properly. So, I do not know how to proceed now.

  • 1

    Have you tried doing the str_replace uppercase with accent for lowercase and only then remove the accent? Since you said it worked in lowercase, maybe you can cheat like this..

  • 1

    Better, use strtolower() to put the whole sentence in lowercase, remove the accent with your function tirarAcentos($string) and then you capitalize everything with strtoupper().. try to see if it works :)

  • Watch the return:

  • Recent Name: GPA - GRUPO PÃO DE ACUCAR Name Updated: GPA - GRUPO PÃO DE ACUCAR Reason Updated: GPA - GRUPO PAO DE ACUCAR - Query: UPDATE ang_cliente SET name = ' GPA - GRUPO PÃO DE ACUCAR', reason = 'GPA - GRUPO PAO DE ACUCAR -' CD_CLIENTE = '460'

  • From the social reason he removed, and the name did not... Uai!

  • 1

    >>>>> http://answall.com/a/72821/3635

  • 1

    Very strange @Andrébaill ! Try what Guilherme Nascimento put in the link above to see if it works

Show 12 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.