Re: using preg_replace or equivelent

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

 



Try str_replace.

$string = "whatever";
$invalidChars = array("(", ")", "\\", "\"", "'"); //put whatever characters here
trim(str_replace($invalidChars, "",$string))

----- Original Message ----- From: "Derek C Hopkins" <derek.hopkins@xxxxxxxxxxxx>
To: <php-windows@xxxxxxxxxxxxx>
Sent: Wednesday, January 31, 2007 1:10 PM
Subject:  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@xxxxxxxxxxxx
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


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

  Powered by Linux