PHP: Replace city name -
I want to match an array against the string and want to change the name of the city in a string with a dash (-) For example: I want to change the following strings below, Thus if the last word is a city then it should be added before the dash (-). Or if the last word is the city and the last word is "IN", then "IN" should be replaced by a dash (-). You can just do it with it. $ str = 'French tuition in New Yorker' or $ str = 'French Tuition New York'; $ ArrCity = array ('Newyork', 'Washington');
$ str = 'French tuition - New York' and $ str = 'French tuition - New York ';
& lt ;? Php $ str = 'French Tuition in New Yorker'; $ Str2 = 'French Tuition New York'; $ ArrCity = array ('Newyork', 'Washington'); $ Temp = array (); $ Partition = explosion ("", $ str); $ Last word = $ partition [count ($ partition) -1]; $ FirstListworld = $ partition [count ($ partition) -2]; If (in_array ($ lastword, $ arrCity)) (if (stroller ($ beforeLastWord) === 'in') {$ split [count ($ split) -2] = '-';} and {$ partition [count ($ Partition) -1] = '-'; array_push ($ partition, $ last word);}} echo fonts ("", $ partition);? & Gt;
Comments
Post a Comment