digitalecartoons — 2007-11-04T05:58:47-05:00 — #1
For a name regular expression which also should allow accented characters like in René, I made this regex:
Is my use of À-ÿ good for that? I got that from the html entity list. Saw that all accented characters fell into that range.
But I've also just read about the alpha class which should take care of that? So I could also use this? And did I wrote it correct?
jake_arkinstall — 2007-11-04T05:59:45-05:00 — #2
digitalecartoons — 2007-11-04T06:22:50-05:00 — #3
Just did. Think alpha is just the same as A-Z...
But just discovered that you can also use hex values in a php regex with \x. Looked up the hex values for acceted characters and this worked:
But is there anything wrong with using À-ÿ? Or is it safer to use hex values in that case?
jake_arkinstall — 2007-11-04T06:24:31-05:00 — #4
I don't think theres anything wrong with Á-ÿ, otherwise there would be an error. Watch out that you don't change the page encoding, though.
digitalecartoons — 2007-11-04T06:25:48-05:00 — #5
If I where to change the page encoding, would that also mean that my hex codes wouldn't be the same?
kieran_in — 2007-11-04T06:28:18-05:00 — #6
You need to use \pL as a modifier after each set of characters.
Then use \u
Search for a regex tutorial. Should help you:)
jake_arkinstall — 2007-11-04T06:28:35-05:00 — #7
Beat me to it^
No, but in my experience, characters like Á could be completely different. If you don't change your encoding, it'll be fine
kieran_in — 2007-11-04T06:32:05-05:00 — #8
digitalecartoons — 2007-11-04T07:04:51-05:00 — #9
You mean when I use hex values like in
stereofrog — 2007-11-04T07:07:24-05:00 — #10
The "alpha" class (correct syntax is [:alpha:]) matches any "letter". The meaning of "letter" depends on the locale, in en-US locale this includes A-Z and accented characters in ISO-8859 encoding.
You can easily find out what it does on your system using a test code like this:
$all = implode(' ', range("!","\\xFF"));
'<font color=red>$0</font>', $all);
digitalecartoons — 2007-11-04T07:37:32-05:00 — #11
I've tried this:
But is says 'false' when entering René or Rene?
And what's this about having to use "\pL as a modifier" ?
stereofrog — 2007-11-04T07:42:41-05:00 — #12
^[[:alpha:]a-zA-Z] doesn't make any sense (nor does "\pL" )
What does this do for you
echo preg_match('/^[[:alpha:]]+$/', 'René');
digitalecartoons — 2007-11-04T08:06:03-05:00 — #13
Tested ^[[:alpha:]]+$ on:
Though it accepts normal letters like in 'rene'
it doesn't allow accented ones like in 'rené'
digitalecartoons — 2007-11-04T10:12:05-05:00 — #14
What should I do to have [[:alpha:]] also allow for accented letters besides A-Za-z?
I've set the browser to chartype iso 8859-1 allready...
kyberfabrikken — 2007-11-04T11:27:36-05:00 — #15
Because of your locale setting. Try setting it to something, which contains those characters, using setlocale.
bokehman — 2007-11-04T11:33:05-05:00 — #16
Either set the correct locale setlocale() (not always possible) or include the individual characters in the regex character class.
digitalecartoons — 2007-11-04T13:06:09-05:00 — #17
Or otherwise just use hexcodes like in this?
(the main page which calls this php script is set by default with a charset of iso-8859-1 anyway)
digitalecartoons — 2007-11-04T13:16:44-05:00 — #18
Does a php server have a standard charset setting? The hex codes work even if I haven't set the charset in the php script specifically. Or is that because my browser has a default setting of iso8859?
digitalecartoons — 2007-11-04T14:24:47-05:00 — #19
This encoding should allways be iso 8859-1?
I've already set the index.php as iso 8859-1 and all posted values are first converted to iso 8859-1 with utf8_decode, so names like René display as René in sent email (and not with funny codes).
kyberfabrikken — 2007-11-04T14:41:53-05:00 — #20
Encoding and locale are different issues. PHP assumes that strings are ISO-8859-1.
Browsers will send data back, using the same charset as the page was served in. Thus you shouldn't use utf8_decode on incoming data.
next page →