Jump to content

[SOLVED] finding special characters in string


earmsby

Recommended Posts

Hi,

 

I'm a bit stumped on this one and it's possible this should really go in the REGEX forum but I'm not sure.  Here's what I'm trying to do:

 

I have a string/word that may have special characters within it (ex. Andrée).  I want loop through the word and compare each letter with a list of special characters and a replacement letter that is a non-special character (ex. é would be replaced by e).

 

In the process of trying to figure out how to do this, I made a little script that loops through the word and puts each letter in an array.  To my surprise, there are more elements in the array than I expected.  The accented e seems to take two spots in the array.  When I print_r the array, I get:

 

Array
(
    [0] => A
    [1] => n
    [2] => d
    [3] => r
    [4] => �
    [5] => �
    [6] => e
)

 

So, I'm confused about how PHP is interpreting the special character.

 

I tried to read in both the PHP online documentation as well as a PHP programming book I have about this but nothing I read really clarified for me what was going on with this.

 

Can anyone help me understand how to approach this seemingly simple problem?

 

Thanks!

  • 2 weeks later...

It's been a little while since I posted this question and received the response from thorpe, so my apologies for resurrecting an old thread.

 

The suggestion worked fine as long as I manually supplied the array of substitution characters into the PHP code.  However, when I tried to pull the array from a MYSQL database the characters don't seem to be the same.

 

The letters/character were added to the DB using php code by simply pasting the character into a form which runs an INSERT query into the table of letter substitutions.

 

There must be some encoding issues between MYSQL and PHP that I'm not understanding. ???

 

Latin1 but I also tried utf to no avail.

 

I may end up just hard coding the substitutions if I can't make it work with the database but I'd still be interested in know how for other situations where I need to work with database encoding and php.

Doh!

 

I just solved my own problem... since the replacement characters will be run against another table in the same database, the character encoding is not a problem.  We are comparing apples to apples.  The problem was when I was either using characters from the database compared against characters typed in or characters hard-coded in against words in the database.

 

:)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.