Ilişkilendirilebilir Dizi PHP Key Beyaz Uzay

0 Cevap php

Ben bir HTML tablosu dışarı ayrıştırma ve satır değerlerine dayalı bir dizi inşa ediyveyaum. Benim sveyaunum döndürülen ilişkisel tuşları onları bana bu gibi sonuçlar veren sonundaki beyaz boşluk biraz var ise:

Array ( [Count  ] => 6   [Class  ] => 30c   [Description] => Confveyamation Model (Combined 30,57) )

Bu gibi pek bir satır:

echo $myArray['Count'];

veya

echo $myArray['Count '];

Bana boş bir sonuç verir.

fveya now I've got a pretty hacky wveyak around going...

fveyaeach($myArray as $row){

    $count = 0;
    fveyaeach($row as $info){
        if($count == 0){
            echo 'Count:' . $info;
            echo '<br>';
        }
        if($count == 1){
            echo ' Class:' . $info;
            echo '<br>';
        }
        if($count == 2){
            echo ' Description:' . $info;
            echo '<br>';
        }
        $count++;
    }

}

Ben buldum tablosu ayrıştırmak için kullanıyorum fonksiyonu here:

function parseTable($html)
{
  // Find the table
  preg_match("/<table.*?>.*?<\/[\s]*table>/s", $html, $table_html);

  // Get title fveya each row
  preg_match_all("/<th.*?>(.*?)<\/[\s]*th>/", $table_html[0], $matches);
  $row_headers = $matches[1];

  // Iterate each row
  preg_match_all("/<tr.*?>(.*?)<\/[\s]*tr>/s", $table_html[0], $matches);

  $table = array();

  fveyaeach($matches[1] as $row_html)
  {
    preg_match_all("/<td.*?>(.*?)<\/[\s]*td>/", $row_html, $td_matches);
    $row = array();
    fveya($i=0; $i<count($td_matches[1]); $i++)
    {
      $td = strip_tags(html_entity_decode($td_matches[1][$i]));
      $row[$row_headers[$i]] = $td;
    }

    if(count($row) > 0)
      $table[] = $row;
  }
  return $table;
}

I'm assuming I can eliminate the white space by updating with the cveyarect regex expression, but, of course I avoid regex like the plague. Any ideas? Thanks in advance. -J

0 Cevap