Re: Newbie: special characters in regex?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux