I need to extract a word from a string and then add it to the end of the string. e.g. $name = "The Smokey Boys" I need to change this to: $name = "Smokey Boys, The" Up to now I have used: $temp = split(" ",$name); if ($temp[0] == "The ") $name = $name - $temp[0]; $name = $name . ", " . $temp[0]; This returns: "The Smokey Boys, The" which means that the first "The" is not being removed. Can anybodt advise me how to solve this problem. Thanks John C
The following line : $name = $name - $temp[0]; is not correct, as - is a mathematical operation. So you should replace it by : $name = substr($name, 4, strlen($name) - 4);
Many thanks for such quick relpies. I have now solved the problem with this bit of code: $temp = split(" ",$name); if ($temp[0] == "The") { $name = substr($name, 4, strlen($name) - 4); $name = $name . ", " . $temp[0]; } Can anybodt forsee any problems with this ??? I now need to know how to make the "The" case insensitive. Can anybody help with this ?? Thanks, John C
Hello, just replace your actual if by : if (strtolower($temp[0]) == "the") to make it case insensitive.
Many thanks Freud2002... I have now got what I was looking for. Your help very much appreciated - THANKS John C