Re: using preg_replace or equivelent

From: Date: Wed, 31 Jan 2007 21:05:01 +0000
Subject: Re: using preg_replace or equivelent
References: 1 2  Groups: php.windows 
Request: Send a blank email to php-windows+get-27427@lists.php.net to get a copy of this message
Hi Terry
        Program now working like a charm.  Your solution was what the doctor ordered.  THANK'S
At 02:15 PM 31/01/2007, Phillip Terry wrote:
Try str_replace. $string = "whatever"; $invalidChars = array("(", ")", "\\", "\"", "'"); //put whatever characters here trim(str_replace($invalidChars, "",$string)) ----- Original Message ----- From: "Derek C Hopkins" <derek.hopkins@sympatico.ca> To: <php-windows@lists.php.net> Sent: Wednesday, January 31, 2007 1:10 PM Subject: [PHP-WIN] using preg_replace or equivelent
Hi All
        Not knowing cgi-script I am having trouble understanding the preg_replace function in PHP.
        What I want to do is remove all ocurances of the following items from a string
        All spaces, open brackets,  close brackets,  apostriphy, and period (full stop)
        from a string  such as these
Audlin,Mary Ann,Spalding,14,412 Audsley,David.,Leeds,23,354 Audsley,David (Male),Leeds,23,354 Audsley,David O'Shannesey,Leeds,23,354 My thoughts were the following code But it does not work # need to remove punctuation in forname, ( . ) ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ $patterns[0] = '/./'; $pattern[1] = '/(/'; $pattern[2] = '/)/'; $pattern[3] = "'"; $pattern[4] = '/ /'; $replacements[0] = "-"; $replaements[1] = "2"; $replacements[2] = "3"; $replaements[3] = "4"; $forname = preg_replace($patterns,$replacements ,$forname); $surname = preg_replace($patterns,$replacements ,$surname); What happens is all characters get changed to - (the first 0 replacement. Any help with this or another solution would be appreciated. Cheers Derek
Derek C Hopkins,                     Phone    +1(450)678-7768
6640, Biarritz,                          Fax      +1(450)678-4252
Brossard,                                E-Mail derek.hopkins@sympatico.ca
QC, Canada, J4Z-2A2. ==== FreeBMD - England and Wales - Birth - Marriage and Death Transcriptions <http://FreeBMD.rootsweb.com> ==== Check out FreeBMD Scan2 Syndicate page (revised daily) Please bookmark our new home http://www.scan2.ca/scan2.html ==== Check out QFHS Marriage Transcription Project page (revised daily) (Quebec Family History Society) Please bookmark our new home http://www.scan2.ca/qfhs.html Check out my web page (22jan1997) Last Revised 28 May 1998 <http://www.cam.org/~hopkde/index.html> Check out Abney Park Indexing Project (revised 14 MAR 2000, 195,000 names) <http://www.cam.org/~hopkde/abney.html> Check out my web Ramsgate page <http://members.adept.co.uk/hopkde> Check out the Quebec Family History web page <http://www.qfhs.ca/index.html> -- 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
Cheers Derek
Derek C Hopkins,                     Phone    +1(450)678-7768
6640, Biarritz,                          Fax      +1(450)678-4252
Brossard,                                E-Mail   derek.hopkins@sympatico.ca
QC, Canada, J4Z-2A2. ==== FreeBMD - England and Wales - Birth - Marriage and Death Transcriptions <http://FreeBMD.rootsweb.com> ==== Check out FreeBMD Scan2 Syndicate page (revised daily) Please bookmark our new home http://www.scan2.ca/scan2.html ==== Check out QFHS Marriage Transcription Project page (revised daily) (Quebec Family History Society) Please bookmark our new home http://www.scan2.ca/qfhs.html Check out my web page (22jan1997) Last Revised 28 May 1998 <http://www.cam.org/~hopkde/index.html> Check out Abney Park Indexing Project (revised 14 MAR 2000, 195,000 names) <http://www.cam.org/~hopkde/abney.html> Check out my web Ramsgate page <http://members.adept.co.uk/hopkde> Check out the Quebec Family History web page <http://www.qfhs.ca/index.html>

« previous php.windows (#27427) next »