Closed Thread Icon

Topic awaiting preservation: preg_replace using arrays not always working... Pages that link to <a href="https://ozoneasylum.com/backlink?for=26589" title="Pages that link to Topic awaiting preservation: preg_replace using arrays not always working..." rel="nofollow" >Topic awaiting preservation: preg_replace using arrays not always working...\

 
Author Thread
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 09-05-2005 02:13

Greetings!

I'm using two arrays to clean up some data I'm fetching. But I'm having a problem with a couple of the entries.
Here are the two arrays:

code:
$search = array (
	"'Twsp'i",
	"'Twshp'i",
	"'Twnshp'i",
	"'Twp'i",
	"'Hts'i",
	"'Hgts'i",
	"'Centerline'i",
	"'Fairhaven'i",
	"'Rosevillen'i",
	"'^Rosevill$'i",
	"'St Clair Shores'i",
	"'Harriston'i",
	"'^Washington$'i",
	"'^Sterling Height$'i",
	"'Sterlingheights'i",
	"'Sterlingheigheights'i",
	"'Sterlingheigheights'i",
	"'MT CLEMENS'i",
	"'MTCLEMENS'i",
	"'CHESTEFIELD'i",
	"'Rosevile'i",
	"'^MACOMB$'i",
	"'^CHESTERFIELD$'i",
	"'^RILEY$'i",
	"'BLOOMFEILDHILLS'i",
	"'BLOOMFIELDHILLS'i",
	"'COMERCETOWNSHIP'i",
	"'FARM HILLS'i",
	"'/FARMINGTON HILL/'i",
	"'FARMINGTONHILLS'i",
	"'FERNDALED'i",
	"'HAZEL PARKQ'i",
	"'MADISON HEIGHEIGHTS'i",
	"'PONTAIC'i",
	"'ROCHESTER HLS'i",
	"'ROSHESTER HILLS'i",
	"'ST CLAIR SHRS'i",
	"'STERLING HGHEIGHTS'i",
	"'W BLOOMFIELD'i",
	"'/WARR/'i",
	"'WATERFPRD'i",
	"'/CLA/'i",
	"'/FAH/'i",
	"'/CLINTON TOWNSHI/'i",
	"'/FARMINGTON HILL/'i",
	"'/WATEROFRD/'i"
);

$replace = array (
	"TOWNSHIP",
	"TOWNSHIP",
	"TOWNSHIP",
	"TOWNSHIP",
  "HEIGHTS",
  "HEIGHTS",
  "CENTER LINE",
  "FAIR HAVEN",
  "ROSEVILLE",
	"ROSEVILLE",
	"SAINT CLAIR SHORES",
	"HARRISON",
	"WASHINGTON TOWNSHIP",
	"STERLING HEIGHTS",
	"STERLING HEIGHTS",
	"STERLING HEIGHTS",
	"STERLING HEIGHTS",
	"MOUNT CLEMENS",
	"MOUNT CLEMENS",
	"CHESTERFIELD",
	"ROSEVILLE",
	"MACOMB TOWNSHIP",
	"CHESTERFIELD TOWNSHIP",
	"RILEY TOWNSHIP",
	"BLOOMFIELD HILLS",
	"BLOOMFIELD HILLS",
	"COMMERCE TOWNSHIP",
	"FARMINGTON HILLS",
	"FARMINGTON HILLS",
	"FARMINGTON HILLS",
	"FERNDALE",
	"HAZEL PARK",
	"MADISON HEIGHTS",
	"PONTIAC",
	"ROCHESTER HILLS",
	"ROCHESTER HILLS",
	"SAINT CLAIR SHORES",
	"STERLING HEIGHTS",
	"WEST BLOOMFIELD",
	"WARREN",
	"WATERFORD",
	"CLAWSON",
	"FARMINGTON HILLS",
	"CLINTON TOWNSHI",
	"FARMINGTON HILLS",
	"WATERFORD"
);



and then I use

code:
$profile[city] = preg_replace($search, $replace, $profile[city]);



To actually use the two arrays. In $search, about 5 from the bottom, you'll see
"'/CLA/'i",

But that doesn't seem to do anything, nor does the one for
"'/FHA/'i",
"'/WARR/'i",
and some others. Most of the array items work fine, however.

As I understand it, the method I have should work on EXACT matches of each of those.

Do I have some bad syntax, or am I just looking at something right in front of me and not realizing it?

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 09-05-2005 21:53

Since you're actually allowed to use any delimeter It may be that
"'/CLA/'i"


Is actually looking for /CLA/ instead of CLA, where normally you use the / / for delimeters you end up using ' '

I'd try using "/CLA/i" instead.



.:[ Never resist a perfect moment ]:.

« BackwardsOnwards »

Show Forum Drop Down Menu