Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4552982
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:52:51+00:00 2026-05-21T16:52:51+00:00

I have a problem with a PHP code that transforms accent characters in non

  • 0

I have a problem with a PHP code that transforms accent characters in non accent characters. I have this code working a year ago but I’m trying to get this to work but without success. The translation is not done correctly.

Here is the code:

<?php

echo accentdestroyer('azeméis');

    /**
     * 
     * This function transform accent characters to non accent characters
     * @param text $string
     */
    function accentdestroyer($string) {
        $string=strtr($string,
        "()!$?: ,&+-/.ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ"
        ,
        "-------------SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy");

        return $string;
    }

?>

I have tested to save the document in UTF-8 but gives me something like this: “azemy�is”

Some clues on what can I do to get this working correctly?

Best Regards,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:52:51+00:00Added an answer on May 21, 2026 at 4:52 pm

    A better solution may be to transliterate those characters automatically using iconv().

    As for the reason your function doesn’t work, it may have something to do with the fact that echo strlen('Š'); outputs 2. The documentation explicitly refers to single byte characters.

    Also,

    $a = 'Š';
    
    var_dump(strtr('Š', 'Š', '!')); // string(2) "!�"
    

    So the first byte has been matched but the second one (leftover) isn’t a byte pointing to a valid Unicode character.

    Update

    Here is a workign example using iconv().

    $str = 'ŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚ';
     
    $str = iconv("utf-8", "us-ascii//TRANSLIT", $str); 
     
    var_dump($str); // string(37) "OEZsoezY?uAAAAAAAECEEEEIIII?NOOOOO?UU"
    

    Some characters didn’t quite translate, such as ¥ and Ø, but most did. You can append //IGNORE to the output character set to silently discard the ones which don’t transliterate.

    You could also drop all non word characters too using a Unicode regex with \pL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some PHP code that should cause and catch two exceptions: try{ @$this->connector->connect();
I have the problem, that PHP replaces all spaces with underscores in POST and
i have a problem, i'm working on a gallery php script and need help,
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have a website that use this style : /index.php?page=45&info=whatever&anotherparam=2 I plan to have
I have a problem regarding display PHP code (stored in a database) on a
I have some PHP code that inserts a date into a table: INSERT INTO
I have a problem in integrating PHP and JQuery: My main file is MyFile.html
I have been having some problems trying to get my PHP running. When I
I have problem in some JavaScript that I am writing where the Switch statement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.