Re: String Help

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

 



This seems to work:

$pattern = "/(\w+) (?:(?:\w\.|\(\w+\))) (\w+)/" ;
$replacement = "\$1 \$2" ;

//$string = "John D. Smith" ;
$string = "Joanne (Taylor) Smith" ;

echo preg_replace( $pattern, $replacement, $string ) ; 

HTH
Ignatius
_________________________
----- Original Message ----- 
From: "Herhuth, Ron" <Ron.Herhuth@tatumpartners.com>
To: <php-windows@lists.php.net>
Sent: Thursday, November 06, 2003 2:54 PM
Subject:  String Help



I have an instance where I am trying to remove a couple different string
scenerios from a variable.  I have spent some time with regEx but I'm not
getting anywhere.  I'm hoping someone could help me out here.

Basically I have names that MAY contain middle initials which I need to
remove:

John D. Smith

I need to strip the "D." so that I have only John Smith

In addition I have a few instances where the name contains a secondary
last name in parentheses that I need to remove:

Joanne (Taylor) Smith

I need to strip the Taylor so that I am left with Joanne Smith.

If anybody could help me with this I would be very appreciative.

Ron



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

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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux