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: $ str = 'French tuition in New Yorker' or $ str = 'French Tuition New York'; $ ArrCity = array ('Newyork', 'Washington');

I want to change the following strings below,

  $ str = 'French tuition - New York' and $ str = 'French tuition - New York ';   

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.

  & 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

Popular posts from this blog

c# - passing input text from view to contoller with FacebookContext using Facebook app -

ios - Does Core Data autoupdate a many to many relationship on saving -

Calling a C++ function from C# by passing a string with variable size to it -