Тут такое дело... Решил протестировать как работает foreach и удивился... Попробуйте у себя запустить. PHP: <? $array = array( 'one'=>'1', 'two'=>'2', 'three'=>'3', 'four'=>'4', 'five'=>'5' ); $string = '<p>i-one<b>|</b>ii-two<b>|</b>iii-three<b>|</b>iv-four<b>|</b>v-five</p>'; foreach($array as $pattern => $replacement) { $string .= preg_replace('/'.$pattern.'/i',$replacement,$string); } echo $string; ?> Я ожидал увидеть что-то вроде такого: i-one|ii-two|iii-three|iv-four|v-five i-1|ii-two|iii-three|iv-four|v-five i-one|ii-2|iii-three|iv-four|v-five i-one|ii-two|iii-3|iv-four|v-five i-one|ii-two|iii-three|iv-4|v-five i-one|ii-two|iii-three|iv-four|v-5 А получилось.. i-one|ii-two|iii-three|iv-four|v-five i-1|ii-two|iii-three|iv-four|v-five i-one|ii-2|iii-three|iv-four|v-five i-1|ii-2|iii-three|iv-four|v-five i-one|ii-two|iii-3|iv-four|v-five i-1|ii-two|iii-3|iv-four|v-five i-one|ii-2|iii-3|iv-four|v-five i-1|ii-2|iii-3|iv-four|v-five i-one|ii-two|iii-three|iv-4|v-five i-1|ii-two|iii-three|iv-4|v-five i-one|ii-2|iii-three|iv-4|v-five i-1|ii-2|iii-three|iv-4|v-five i-one|ii-two|iii-3|iv-4|v-five i-1|ii-two|iii-3|iv-4|v-five i-one|ii-2|iii-3|iv-4|v-five i-1|ii-2|iii-3|iv-4|v-five i-one|ii-two|iii-three|iv-four|v-5 i-1|ii-two|iii-three|iv-four|v-5 i-one|ii-2|iii-three|iv-four|v-5 i-1|ii-2|iii-three|iv-four|v-5 i-one|ii-two|iii-3|iv-four|v-5 i-1|ii-two|iii-3|iv-four|v-5 i-one|ii-2|iii-3|iv-four|v-5 i-1|ii-2|iii-3|iv-four|v-5 i-one|ii-two|iii-three|iv-4|v-5 i-1|ii-two|iii-three|iv-4|v-5 i-one|ii-2|iii-three|iv-4|v-5 i-1|ii-2|iii-three|iv-4|v-5 i-one|ii-two|iii-3|iv-4|v-5 i-1|ii-two|iii-3|iv-4|v-5 i-one|ii-2|iii-3|iv-4|v-5 i-1|ii-2|iii-3|iv-4|v-5 Мб кто-то знает в чем дело?))
PHP: <? $array = array( 'one'=>'1', 'two'=>'2', 'three'=>'3', 'four'=>'4', 'five'=>'5' ); $string[] = '<p>i-one<b>|</b>ii-two<b>|</b>iii-three<b>|</b>iv-four<b>|</b>v-five</p>'; foreach($array as $pattern => $replacement) { $string []= preg_replace('/'.$pattern.'/i',$replacement,$string[0]); } print implode('',$string);
ненадо называть 2 разные переменные одним названием $string = '<p>i-one<b>|</b>ii-two<b>|</b>iii-three<b>|</b>iv-four<b>|</b>v-five</p>'; и $string .= preg_replace('/'.$pattern.'/i',$replacement,$string); вдумайся что делает сама с собой вторая строка
а вот еще PHP: <? $array = array( 'one'=>'1', 'two'=>'2', 'three'=>'3', 'four'=>'4', 'five'=>'5' ); $string_start = '<p>i-one<b>|</b>ii-two<b>|</b>iii-three<b>|</b>iv-four<b>|</b>v-five</p>'; foreach($array as $pattern => $replacement) { $string .= preg_replace('/'.$pattern.'/i',$replacement,$string_start); } echo $string_start.$string;
siiXth Ты прав, спасибо. Alex_pac Спасибо за варианты ответа. Проблема решена так: PHP: <? $array = array( 'one'=>'1', 'two'=>'2', 'three'=>'3', 'four'=>'4', 'five'=>'5' ); $starting_string = '<p>i-one<b>|</b>ii-two<b>|</b>iii-three<b>|</b>iv-four<b>|</b>v-five</p>'; $string = null; foreach($array as $pattern => $replacement) { $string .= preg_replace('/'.$pattern.'/i',$replacement,$starting_string); } echo $string; P.S. Alex_pac, во втором варианте показывет ошибку что не найдена переменная $string где $string .= preg_replac... , а если убрать точку то выдает: i-one|ii-two|iii-three|iv-four|v-five i-one|ii-two|iii-three|iv-four|v-5
Что-то я уж сильно тут тупанул)) Плохо насиловать свой мозг, потом часто не понемаешь очевидные вещи)) Всем еще раз спасибо, спокойной ночи.