markman641
01-25-2012, 01:59 AM
This seems simple but I cant figure it out.
Anyway, I have a string ($country) and inside that string it says "United States, Canada, France, Germany, United Kingdom"
first off this string will vary. What I am trying to do is replace "United States" with US, Canada with CA, and United Kingdom with UK. Now this can be done with:
$country = "United States, Canada, France, Germany, United Kingdom";
$oldword1 = "United States";
$newword1 = "US";
$oldword2 = "Canada";
$newword2 = "CA";
$oldword3 = "United Kingdom";
$newword3 = "UK";
$text1 = str_replace($oldword1 , $newword1 , $country);
$text2 = str_replace($oldword2 , $newword2 , $text1);
$text3 = str_replace($oldword3 , $newword3 , $text2);
echo $text3
Im sure there is an easier way then that but oh well. ANYWAYS, now I want it to take out the "France" and "germany" OR ANY OTHER COUNTRY except us ca and uk... how do I do it?
Thanks will be given to all that help
Anyway, I have a string ($country) and inside that string it says "United States, Canada, France, Germany, United Kingdom"
first off this string will vary. What I am trying to do is replace "United States" with US, Canada with CA, and United Kingdom with UK. Now this can be done with:
$country = "United States, Canada, France, Germany, United Kingdom";
$oldword1 = "United States";
$newword1 = "US";
$oldword2 = "Canada";
$newword2 = "CA";
$oldword3 = "United Kingdom";
$newword3 = "UK";
$text1 = str_replace($oldword1 , $newword1 , $country);
$text2 = str_replace($oldword2 , $newword2 , $text1);
$text3 = str_replace($oldword3 , $newword3 , $text2);
echo $text3
Im sure there is an easier way then that but oh well. ANYWAYS, now I want it to take out the "France" and "germany" OR ANY OTHER COUNTRY except us ca and uk... how do I do it?
Thanks will be given to all that help