using preg_replace or equivelent
using preg_replace or equivelent
am 31.01.2007 20:10:59 von Derek C Hopkins
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
==== 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
Check out Abney Park Indexing Project (revised 14 MAR 2000, 195,000 names)
Check out my web Ramsgate page
Check out the Quebec Family History web page
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: using preg_replace or equivelent
am 31.01.2007 20:15:28 von Phillip Terry
Try str_replace.
$string = "whatever";
$invalidChars = array("(", ")", "\\", "\"", "'"); //put whatever characters
here
trim(str_replace($invalidChars, "",$string))
----- Original Message -----
From: "Derek C Hopkins"
To:
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
>
>
> ==== 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
>
>
> Check out Abney Park Indexing Project (revised 14 MAR 2000, 195,000 names)
>
>
> Check out my web Ramsgate page
>
>
> Check out the Quebec Family History web page
>
> --
> 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
Re: using preg_replace or equivelent
am 31.01.2007 22:05:01 von Derek C Hopkins
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"
>
>To:
>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
>>
>>
>>==== 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
>>
>>
>>Check out Abney Park Indexing Project (revised 14 MAR 2000, 195,000 names)
>>
>>
>>Check out my web Ramsgate page
>>
>>
>>Check out the Quebec Family History web page
>>
>>--
>>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
==== 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
Check out Abney Park Indexing Project (revised 14 MAR 2000, 195,000 names)
Check out my web Ramsgate page
Check out the Quebec Family History web page
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php