Friday 15 July 2011

php - str_replace string and similar string -


I am trying to use the str_replace () function with an array of strings.

My problem is that there is some other string in some strings in my array.

Here's an example:

I have a range of products such as: $ product1 = 'COLLIERPEND'; $ Product2 = 'colier';

And I want to convert them all to co .

  str_replace (array ("COLLIER", "COLLIERPEND"), 'with', $ product #);   

The result is:

  $ product1 = 'coPEND'; $ Product2 = 'cum';   

I could just change the order in the array, but I have many categories.

Is there a function that can help me get desired results? Take a look at

, replace \ bCOLLIER \ b with co Search for In this way you are getting word limits on each side of the search term, so you should not get sub-word problems.

Optionally (because I can not fully understand your problem) Sort your list by length, first of all first



No comments:

Post a Comment