Re: Newbie: special characters in regex?
| From: | Al | Date: | Tue, 25 Sep 2007 15:21:20 +0000 |
| Subject: | Re: Newbie: special characters in regex? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262455@lists.php.net to get a copy of this message | ||
Suggest using the hex or oct codes for the special characters. It will save you much heart ache. Here is a great utility http://www.dextronet.com/charprobe.php
Zembower, Kevin wrote:
I'm trying to modify a string so that it can be used as a Distinguished Name in an LDAP operation. Distinguished Names must have special characters, such as (, ), / and \ escaped with a backslash. For instance, 'Kevin (Kev) Zembower, III" becomes 'Kevin \(Kev\) Zembower\, III'. I tried to do this in this statement: $entry['FirstName'] = preg_replace('/(\)|\(|\,|\/)/',`\\$1', $entry['FirstName']; But it gives me this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/centernet/htdocs/ldap_auth/conversion.php on line 89 Can anyone help me get this statement right? Also, this doesn't seem very readable or easily maintained. I read about using an array() as the pattern string, which might make the statement more readable. Can anyone show me how this would be done, and suggest other ways to make this statement more easily maintained? Thanks for your advice and suggestions. -Kevin Kevin Zembower Internet Services Group manager Center for Communication Programs Bloomberg School of Public Health Johns Hopkins University 111 Market Place, Suite 310 Baltimore, Maryland 21202 410-659-6139