How to remove accent text in php?

Asked

Viewed 188 times

1

I have the following situation, the text below it has the following words ATENÇÃO: and será that in turn they are accented, they should be removed from the text but due to accents I cannot remove.

$string = "ATENÇÃO: O produto será revisado e constatado o defeito será";

$remover = array ("ATENÇÃO:","será");

echo $texto = str_replace("$remover","",$string);

Expected result.

The product reviewed and found the defect

2 answers

3


Your logic works perfectly with accents, the problem is that you are transforming the array with elements to remove in a string.

Look at the following, I just changed the statement of array for short syntax and removed the extra quotes:

<?php

$string = "ATENÇÃO: O produto será revisado e constatado o defeito será";

$remover = ["ATENÇÃO:","será"];

echo $texto = str_replace($remover, "", $string);

See working here.

PS.: Watch out for error messages, run its original function was returning the following error:

Notice: Array to string Conversion in /in/fLpSU on line 7

2

Take the double quotes from the variable $remover.

echo $texto = str_replace($remover,"",$string);`

See worked on IDEONE

  • Even apart the double quotes I do not have the expected result.

  • Can you put all the code you are testing, what are inside the php tags ? I tested here and it’s working, I’m just confirming the relationship with the link I put in my reply...

  • My problem is with the answer that the database gives, because visually it appears with the accent, but internally it appears special characters, when doing the test isolated as I put in the example it sure, as your answer worked, but when I use $Row['text'] the result is another.

  • So, like I said put the real code you’re using...

  • I was able to solve with these functions utf8_encode and utf8_decode

Browser other questions tagged

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