PHP Foreach döngü ve DOMNodeList Koleksiyonu [yinelenen]

1 Cevap php

Bu soru burada zaten bir cevabı var:

1 Cevap

Aşağıda bir foreach ile bunu nasıl bir örnektir. Her zaman kullanabilirsiniz, ancak $cols->length ayrıca döngüsü kullanarak sorununuzu çözecek listesinde düğümlerin sayısını alır.

 // assume there is an array initialized called outside of the loop for the rows called $lines
  $cols = $row->getElementsByTagName("td");

  $row = array();
  foreach($cols as $item)
  {
    $raw = $item->nodeValue;
    $row[] = '"'.trim(iconv("UTF-8", "ASCII//IGNORE", $raw)).'"';

  }
  $lines[] = implode(',', $row); // turn the array into a line

  // this is outside the loop for rows
  $output = implode("\n", $lines);