Discussions


Chess, Go & Poker Server









                                          
User   Password   remember   (register)  ?

How to remove accents in PHP ?

Poker, chess & Go world championship

Back to programming.


thibault    (2009-04-04)

thibault

 
How to remove accents in PHP ?


Here is a nice function that can help you to remove every accent in a text. It can be useful to build a url that works on a server running an old PHP version or to convert a text from UTF-8 to ISO-8859-1 format.

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


By the way, as UTF-8 should be the most used format in the future, it is strongly recommanded to code all your pages in this format.



(more options below)

*91e551    (2009-09-15 18:40:01)
Let iconv handle it

<?php
// This covers all unicode characters
$text = iconv('UTF-8', 'US-ASCII//TRANSLIT', $text);
?>

Iconv manual at php.net:
http://us2.php.net/manual/en/function.iconv.php


*suvasa    (2010-06-07 13:07:44)
23 months ago

<HEAD>
<?php
/* you need the setlocale if you use a function in the HEAD part of your HTML document; without it the transmission of strings as parameters is flawed from the BODY part to the HEAD part where the function is */

function clearUTF($chaine)
{return iconv('UTF-8', 'ASCII//TRANSLIT', chaine);}
?>
</HEAD>

<BODY>
<?php
setlocale(LC_ALL, 'en_US.UTF8');
$text='un été à Paris';
echo clearUTF($text);
?>
</BODY>


*dave    (2010-11-02 07:26:08)
18 months ago

Hi thibault,

Do you know how to use this function on a php script to remove accents on fields sent to the script from a form via GET ??

So that the script can use then that unaccented fields info..

Your function seems very close for what I need, but I'm not coder, so wouldn't know how to use it.

Thanks!

Dave.


thibault    (2010-11-02 20:57:31)

thibault

18 months ago

Hi Dave,

Obviously your script should look like this:

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

$_GET['whatever'] = replace_accents($_GET['whatever']);


Nothing more !?


*todadu    (2010-11-06 00:55:57)
18 months ago

24 Caprices for Solo Violin, Op. 1-Paganini, Nicolò; Midori, E-flat - Moderato


*patufa    (2011-01-20 14:15:21)
How to remove accents in PHP ?

áéióú áéióú áéióú áéióú áéióú áéióú áéióú


*bikafo    (2011-02-11 15:13:57)
15 months ago

think mister! but you forget things like 'ã©' => 'e' ;)


*devere    (2011-02-24 09:58:22)
14 months ago

Příloha č. 1 k Přiznání k dani z příjmů fyzických osob za zdaňovací období roku 2010 - výpočet dílčího základu daně z příjmů z podnikání a z jiné samostatné výdělečné činnosti (§ 7 zákona)


*gosabe    (2011-03-10 05:51:48)
14 months ago

hi i have problems
?


*vexude    (2011-09-12 10:35:20)
8 months ago

Žluťoučký kůň úpěl ďábelské ódy.


*fozuve    (2012-04-06 18:30:53)
How to remove accents in PHP ?

this is incomplete, not good enough


See also

 Deleting accents with PHP - The solution
en.kioskea > faq/sujet 1005 deleting accents with php

 Remove accents from a string with PHP - PHP tips & trick, misc.
webxadmin.free > article/remove accents from string with php 284.php

 Reading and removing accent characters : accent, charcters
experts exchange > Web Development/Web Languages Standards/PHP/Q 20885211

Subscribe now for full access to Experts Exchange and...
I have a text file with foreign characters Léo but when I read...

 FAQTs - Knowledge Base - View Entry - How do I remove all accent from a string ?
faqts > knowledge base/view.phtml/aid/32273/fid/1

 b2evolution :: View topic - Remove accents in pings
forums.b2evolution > viewtopic.php?t=5192

Wherever I'm going to post the results of my investigations, I'm...
If it works or not, will you be posting the results at this forum and...

 Remove Letter Accents from Text | PHP Text Processing | Hot Scripts
hotscripts > listing/remove letter accents from text

 scriptingBlog.com » Blog Archive » Remove Letter Accents from Text
scriptingblog > php and mysql/remove letter accents from text/39

PHP Link Cloaker: Hide Affiliate Links And Track Visitor...



ficgs
More websites

You must register to see these links, as this is a collaborative page, then you may change the order of the links by clicking the icons before the titles.


 Function Reference/remove accents « WordPress Codex
codex.wordpress > Function Reference/remove accents

 web developer notes: remove accents from strings using postgresql
web dev tip.blogspot > 2007/02/remove accents from strings using

 Download Removing accents in NET 2.0 - Removing accents in NET 2.0 - Removing accents in NET 2.0 with C# - Softpedia
webscripts.softpedia > script/Snippets/Removing accents in NET 2 0 26394

 Removing Accents In a Ruby String - Techniconseils
techniconseils > en/scripts remove accents ruby.php

 Remove Letter Accents from Text : PHP Scripts and Programs Miscellaneous Scripts Directory
advancescripts > detailed/16860

No part of this website may be reproduced, copied and/or distributed...
Trademarks are property of their respective owners Site Developed...
This function will translates all accented characters, from a...

 Re: Problem when removing accents from a String :: ASPN Mail Archive :: ruby-talk
aspn.activestate > ASPN/Mail/Message/ruby talk/3709919

 Removing accents and whitespace from files - WebDeveloper.com
webdeveloper > forum/s

Hi I would like to upload my files and remove any...
java String class has allots of string manipulation...

 Remove accents - Spring for .NET Community Forums
forum.springframework > s

 Function for removing Accents?
velocityreviews > forums/t293027 function for removing accents

How to assign a returns value of a javascript function to a...
If preserving the meaning of your input text data is not...

 How to remove accents (A-Umlaut to A) - bytes
bytes > groups/net/689193

 Source PHP - Chaine de caractères - Remove Accents
comscripts > sources/php.remove accents.4

 Remove accents sql section at Free Download Manager
freedownloadmanager > downloads/remove accents sql info

This tool will search for the presence of duplicate records...
Remove Duplicate - automatically remove duplicate mp3s in...
Want to insert an accented letter or a math symbol such as...

 [wp-svn] [4050] trunk/wp-includes/formatting.php: Faster remove accents.
comox.textdrive > pipermail/wp svn/2006 July/001685

 [#CRM-1439] Google geocode error when processing accented characters - CiviCRM Issue Tracker
issues.civicrm > jira/browse/CRM 1439

Entity: line 1: parser error : Input is not proper UTF-8...
When tyring to geocode an address with french accents an...



admin
Other websites

The following links might be less relevant, please change their ranks if you find them useful.


 Epsilon Clue » Blog Archive » Removing Accents in Strings
ooblick > weblog/2007/01/28/removing accents in strings

Th' Montana GOP, Proudly MARRRchin' Toward th' 19th Century...
Frequently Unanswered Questions about Intelligent...

 Remove the french canadian accents - Zen Cart Support
zen cart > forum/s

Content and Graphics Copyright (c) 2006, 2007, 2008, 2009, 2010...

 Snippets Tagged 'Accents'
snipplr > all/tags/accents

 remove accents and symbols with sed - Shell Programming and Scripting - The UNIX and Linux Forums
unix > shell programming scripting/95859 remove accents symbols sed

Sorry doesn't work me In te text, the caracter ª if I do a...
Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and...
cp first ~/bin what is ~ symbols importance in...

 Remove diacritical / accent marks from text? - The macosxhints Forums
forums.macosxhints > s

 Forms - php and displaying French accents-how to amend the DWCS3 CSS, Ajax book tutorial? - Topic Powered by Infopop
friendsofed.infopop > 4/OpenTopic?a=tpc&s=989094322&f=5283032876&m=6

Added ent_quotes with utf-8 specified to sticky form fields, as seen...

 Use Normalizer to Remove Accents : Normalizer « I18N « Java Tutorial
java2s > Tutorial/Java/0220 I18N/UseNormalizertoRemoveAccents.htm

 Warning: strtr() [function.strtr]: The second argument is not an array in /home/aptana/domains/forums.aptanacloud.com/web/htdocs/includes/session.php...
forums.aptana > viewtopic.php?f=20&t=8234



Response  
  Smilies

Guest name   (optional)       Register for more options.



Trackbacks : If you talked about this article in your blog or website, you may instantly get a backlink 
  There's no trackback at the moment.











 

FICGS message




Discussions



 


Photo blog selected : lol

lol - March 08, 2012   lol - March 07, 2012   lol - March 06, 2012  
A new picture tomorrow morning, around 10 a.m.



 


Pagerank       Copy this code to display your site's Pagerank




Write upside down to your friends!   In your blog, anywhere...
(works with MySpace, Twitter, Facebook, Youtube, MSN, Hi5, Bebo, Yahoo...)






Tip of the day :

You don't know how to find a file to download on Rapidshare or Megaupload ?

You should try this command on Google : site:www.rapidshare.com keywords

Thus you'll also find a particular page on Wikipedia or any link on P2P (emule, eDonkey) sites.



FICGS is also a Free Internet Correspondence Games Server.

Here you can play Chess, Go & Poker Texas Holdem online for free in rated class tournaments and a unique world championship.

Free Internet Chess & Go Server


Feel free to link to this page and to FICGS chess server :