Forum Moderators: coopster

Message Too Old, No Replies

Scanning a string for invalid characters

Such as Ð or Ô

         

Karma

4:09 pm on Apr 26, 2007 (gmt 0)

10+ Year Member



Hi all,

Does anyone know a way of scanning a string to find invalid characters such as Ð or Ô and return a true or false?

I thought it was the "htmlentities" function, but all that does is convert invalid characters to the ascii code.

Many thanks, would be great if someone knows the answer!

henry0

5:18 pm on Apr 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you know what valid chars are or none valid chars are?
If so throw the valid in a regex and check the string against it.
Remember that it is usually easier to define what is allowed VS defining the reverse.
Make it a function that will return true or false so you may easily reuse it across your scripts.
You could also use eregi() to check against disallowed

HoboTraveler

6:24 pm on Apr 26, 2007 (gmt 0)

10+ Year Member



Just create a function that takes a string and checks it for a-z characters. If it contains anything other than a-z, return false!

[edited by: HoboTraveler at 6:24 pm (utc) on April 26, 2007]

Karma

10:25 pm on Apr 26, 2007 (gmt 0)

10+ Year Member



Ok, maybe I should explain the problem a little further...

I am selecting records from a MySQL database:

$query = "SELECT column1,column2,column3 FROM $my_database WHERE character='D'";

As expected, this picks up all records that have 'D' in the character column, however, it also picks up all records that have '' in the character column.

Character set problem maybe? (Currently set to 'latin1')

?

[edited by: Karma at 10:26 pm (utc) on April 26, 2007]

Karma

9:59 am on Apr 27, 2007 (gmt 0)

10+ Year Member



FYI, I changed the character column encoding from latin1 to UTF-8 and the problem has now been resolved.