2011-08-10 50 views
0

我试图用SimpleHTMLDom做一个刮,似乎是运行到一个问题。PHP SimpleHTMLDom抓取问题

我的代码如下:

$table = $html->find('table',0); 
$theData = array(); 
foreach(($table->find('tr')) as $row) { 

    $rowData = array(); 
    foreach($row->find('td') as $cell) { 

     $rowData[] = $cell->innertext; 
    } 

    $theData[] = $rowData; 
} 

function array_find($needle, array $haystack) 
{ 
    foreach ($haystack as $key => $value) { 
     if (false !== stripos($needle, $value)) { 
      return $key; 
     } 
    } 
    return false; 
    } 

$searchString = "hospitalist"; 
$position = array_find($searchString, $theData); 
echo ($position); 

这产生以下错误:

Warning: stripos() [function.stripos]: needle is not a string or an integer in C:\xampp\htdocs\main.php on line 85 

我在做什么错?

+1

它说针是不是字符串,并应 – Ibu

回答

1

the docs,你应该在针过一秒,而不是第一个。试试这个:

function array_find($needle, array $haystack) 
{ 
    foreach ($haystack as $key => $value) { 
     if (false !== stripos($value, $needle)) { 
      return $key; 
     } 
    } 
    return false; 
    }