0

I am using str_replace :

foreach( $languages as $lang ) {
    $html = str_replace( $lang['english'], $lang['german'], $html );
}

The $languages array contains :

$languages = array(array('english'=>'accessories','german'=>'xxxx'),array('english'=>'accessories table','german'=>'yyyyyyyy') );

Now the issue is that it outputs accessories as xxxx and accessories table as xxxxx table instead of outputting accessories table as yyyyyyyy

Aniket Sahrawat
  • 12,410
  • 3
  • 41
  • 67
Isaac
  • 1
  • 1
  • 6

1 Answers1

0

You should replace the "longest" matched term first.

by rearranging your $languages array, it should solve the problem

$languages = array(array('english'=>'accessories table','german'=>'yyyyyyyy'), array('english'=>'accessories','german'=>'xxxx'));
Neverever
  • 15,890
  • 3
  • 32
  • 50