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
For a simple string replacement, why not do something like this
<?php
$FirstName = 'Kevin (Kev) Zembower, III';
echo $FirstName;
$replace[')'] = '\)';
$replace['('] = '\(';
$replace['/'] = '\/';
$replace[','] = '\,';
$FirstName = str_replace(array_keys($replace), $replace, $FirstName);
echo $FirstName;
?>
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php