|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Escaping Chars in Preg Pattern
Hi Dudes
Im taking the value of $myvar and turning it in an "accent insensitive pattern" like, if $myvar = "a simple text" the function i built will return $myvar as: "/[a|á|à|â|ã|ä|å] s[i|í|ì|î|ï]mpl[e|é|è|ê|ë] t[e|é|è|ê|ë]xt/i" but, i fear that some chars in my $myvar may cause preg syntax error (/, [, ] and so on...) So, i believe i need to escape ´em, and thats what i wanted to know: Which chars i need to escape in $myvar to free it from preg syntax errors and how do i escape ´em? Thanks a lot in advance Lui |
|
#2
|
||||
|
||||
|
You can't use preg or ereg functions on what you're trying to do, as these functions will only search the ascii character set. You have to use the php regex functions with multi-byte support, such as mb_ereg.
I've never done this before but do a searh for this function or ones like mb_ereg_replace and you should be on the right track. Good luck. |
|
#3
|
||||
|
||||
|
For accented char preg and ereg work fine because they aren't multi-byte, but if you do goto mb then you'll have to use mb_ereg like colpaarm said. But for now you are fine.
Both of these print out correctly PHP Code:
Now as for your orginal question, you'll have to escape certain chars, Code:
[]\/+*.(){}-|$^
those are the ones I remember offhand, use a backslash to escape them (just like php uses for escaping quotes) sometimes you'll have to use upto 4 or more backslashes to get it to work correctly, this is because of phps string.
__________________
Miscellaneous Software Viper_SB Developershed E-Support Anyone else play chess? Challenge me |
|
#4
|
|||
|
|||
|
the mb functions arent working here
![]() but thanks for the chars! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > Escaping Chars in Preg Pattern |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|