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

  • Home
  • SEARCH
  • 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 1038909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:02:03+00:00 2026-05-16T15:02:03+00:00

I need to compare strings and match names to one another even if they

  • 0

I need to compare strings and match names to one another even if they are not spelled the same way.
For example DÉSIRÉ-Smith should match Desireesmith as well as Desiree or Desi'ree Smith

So I had the following approch which worked perfectly in the command line using PHP-CLI:

    <?
    class Alike {
      static function convertAlike($string) {
        // in case the first and last name or two first names are mixed up
        $parts = preg_split('/[\s\-\.\_]/', $string, -1, PREG_SPLIT_NO_EMPTY);
        sort($parts);
        $string = implode($parts);

        $string = iconv('UTF-8', 'ASCII//TRANSLIT', $string); // transliterate
        $string = strtolower($string); // lowercase
        $string = preg_replace('/[^a-z]/','',$string); // remove everything but a-z
        $string = preg_replace('{(.)\1+}','$1',$string); // remove duplicate chars
        return $string;
      }
      static function compareAlike($string1,$string2) {
        return (strcmp(Alike::convertAlike($string1),Alike::convertAlike($string2)) === 0) ? true : false;
      }
    }
    echo Alike::convertAlike("DÉSIRÉ-Smith").PHP_EOL; // desiresmith
    echo Alike::convertAlike("Desireesmith").PHP_EOL; // desiresmith
    echo Alike::convertAlike("Desi'ree Smith").PHP_EOL; // desiresmith
    echo Alike::convertAlike("René Röyßeå likes special characters ½ € in ©").PHP_EOL; // reneroysealikespecialcharacterseurinc

    var_dump(Alike::compareAlike("DÉSIRÉ-Smith","Desireesmith")); // true
    var_dump(Alike::compareAlike("Desireesmith","Desi'ree Smith")); // true
    var_dump(Alike::compareAlike("summer","winter")); // false
    ?>

However in my website running Server version: Apache/2.2.14 (Ubuntu) running PHP Version 5.3.2-1ubuntu4.2 as module I always get just question signs.
The funny thing is that the error must occour in this line

$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string); // transliterate

because afterwards i can see every character that has not been transliterated, but those that should have been replaced by ascii chars become question signs.

i tried every possible combination of input/output string encoding and iconv internal, input and output encoding settings as well as locale settings. i even did chmod -R 777 /usr/lib/gconv and moved the to my working dir.

however i saw this bug reported ont he mailing list:
http://bugs.php.net/bug.php?id=44096

[2010-06-07 21:22 UTC] icovt at yahoo dot com
mod_php iconv() is not working properly if your apache is chrooted and you do not 
have the content of /usr/lib/gconv/ folder into your relative chroot path (i.e. 
/your/chroot/path/usr/lib/gconv/). 
You can simply do: 
cp /usr/lib/gconv/* /your/chroot/path/usr/lib/gconv/
... and re-try.

This was a fix for me, hope this could save time for somebody else.

P.S. Btw, initially iconv() called from command line (using php cli) was OK.

I tried that my www-data user is at home in /var/www/ and I ended up with the folder /var/www/usr/lib/gconv/ as well as /var/www/myproject/usr/lib/gconv/

FYI: I had encoding detection and transcoding functions to ensure the correct encodings to be passed, but removed them for the sake of clarity as they are not needed anwyay if you input utf8 strings everything should be fine…

Any ideas?

  • 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-16T15:02:04+00:00Added an answer on May 16, 2026 at 3:02 pm

    figured out that the locale wasnt set up correctly and my attempts to set it failed as they locales available on the system were actually named different then the manpage examples (according to their encoding!)
    a simple locale -a revealed that ;O)

    setlocale(LC_ALL, "en_US.utf8");
    

    this actually did the job!

    well now this function works perfectly.

    well now ita clear why it worked from the console as well, because the locale was imported from the current users shell settings 😉
    it actually just needs any locale set up. doesnt really matter which one as we convert to ascii where everybody is equal, only some are more equal than others 🙂

    Be careful to set a locale that is actually installed in your system and check the result of setlocale, because you won’t change anything if the locale is not installed or name is misspelled.

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

Sidebar

Related Questions

No related questions found

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.