PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 10th, 2005, 12:20 PM
luigui luigui is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 133 luigui User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 47 m 22 sec
Reputation Power: 5
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

Reply With Quote
  #2  
Old May 10th, 2005, 12:45 PM
colpaarm's Avatar
colpaarm colpaarm is offline
300lb Bench!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2001
Location: New York
Posts: 2,198 colpaarm User rank is Sergeant (500 - 2000 Reputation Level)colpaarm User rank is Sergeant (500 - 2000 Reputation Level)colpaarm User rank is Sergeant (500 - 2000 Reputation Level)colpaarm User rank is Sergeant (500 - 2000 Reputation Level)colpaarm User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 31 m 13 sec
Reputation Power: 18
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.

Reply With Quote
  #3  
Old May 10th, 2005, 01:14 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,798 Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 20 m 33 sec
Reputation Power: 476
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:
print '<pre>';
preg_match('/à/i''testà'$matches);
print_r($matches);

eregi('à''testà'$matches);
print_r($matches); 


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

Reply With Quote
  #4  
Old May 10th, 2005, 02:29 PM
luigui luigui is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 133 luigui User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 47 m 22 sec
Reputation Power: 5
the mb functions arent working here

but thanks for the chars!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Escaping Chars in Preg Pattern


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT