We have a cycle:

$i = 0; while($count>$i) { $bvc = trim($slovo[$i]); $trans = array($bvc => ' '); $chist = strtr($tova, $trans); $i++; } echo $chist; 

We need to output the data from the $ chist variable, where all entries should be deleted. Now one entry is deleted - the last one.

Complete script (with fix from KiTE, does not work):

 $trr = '<div class="category"><a href="#" rel="tag" title="">продукция</a> <a href="#" rel="tag" title="">хозяйство</a> <a href="#" rel="tag" title="">хранение</a></div>'; $sttr = $trr.'<div class="actions_tags"><a href='#'>продукция</a>, <a href='#'>хранение</a></div>'; preg_match('|<div class="category">(.*)</div>|Uis', $sttr, $p_category); preg_match('|<div class="actions_tags">(.*)</div>|Uis', $sttr, $p_keywords); $p_keywords[1] = strip_tags($p_keywords[1]); $p_category[1] = strip_tags($p_category[1]); $explode = explode(",", $p_keywords[1]); $exp_count = count($explode); $ing = 0; //Начало исправления KiTE $chist = ''; while($exp_count>$ing) { $bvc = trim($explode[$ing]); $trans = array($bvc => ' '); $chist .= strtr($p_category[1], $trans); $ing++; } echo $chist; //Конец 

The contents of $ trr and $ sttr are constantly changing.

  • 2
    why torture the code and yourself, use for, and with the solution of the question, you need to think about for ($ i = 0; $ i <$ count; $ i ++) {$ bvc = trim ($ slovo [$ i]); $ trans = array ($ bvc => ''); $ chist = strtr ($ tova, $ trans); } - oxyage 7:01 pm
  • oxyage, I used to use while, I know about for, but anyway, thanks! - nick777

1 answer 1

 $i = 0; $chist = ''; while($count>$i) { $bvc = trim($slovo[$i]); $trans = array($bvc => ' '); $chist .= strtr($tova, $trans); $i++; } echo $chist; 
  • It displays $ i times the content of $ tova, i.e. $ i times the content without all replacements. - nick777
  • So the problem is somewhere else in the code. The question is "How to collect data from each iteration of the loop into one variable." I answered him exactly. The 2nd line pre- $chist variable, and the 6th line adds the result from strtr($tova, $trans) to the end of this variable in each iteration of the loop. To debug your code, I recommend echo strtr($tova, $trans); inside the loop. What would you see that this function - KiTE
  • Showed the script completely, it is very small, the output of strt did not give anything - the same thing is issued. - nick777