Hey, this is my first post on stackoverflow.
I'm trying to replace é with e and other similar special characters. I've tried str_replace() and converting it from UTF-8 to ASCII but nothing seems to work. When I convert it from UTF-8 to anything it just drops the é off. When I use str_replace() it never catches it and the é is still there.
I have a feeling something is wrong internally on our server because my friend tried str_replace() on his server and it worked fine.
Thanks,
Jason Tolhurst
If you do spot something please leave a comment and we will endeavour to correct. The PHP function preg_replace () has powerful functionality in its own right, but extra depth can be added with the inclusion of the e modifier. Take the following bit of code, which just picks out the letters of a string and replaces them with the letter X.
Take the following bit of code, which just picks out the letters of a string and replaces them with the letter X. This is simple enough, but using the e modifier allows us to use PHP functions within the replace parameters.
The str_replace () function replaces some characters with some other characters in a string. This function works by the following rules: If the string to be searched is an array, it returns an array. If the string to be searched is an array, find and replace is performed with every array element.
A faster way to replace the strings in multidimensional array is to json_encode() it, do the str_replace() and then json_decode() it, like this: <?php. function str_replace_json($search, $replace, $subject){.
$string = iconv('utf-8','ASCII//IGNORE//TRANSLIT',$string);
You can use htmlentities()
to convert é
to é
and then use a regex to pull out the first character after an ampersand.
function RemoveAccents($string) {
// From http://theserverpages.com/php/manual/en/function.str-replace.php
$string = htmlentities($string);
return preg_replace("/&([a-z])[a-z]+;/i", "$1", $string);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With