gpt4 book ai didi

php - fatal error : Cannot use object of type DOMNodeList as array

转载 作者:可可西里 更新时间:2023-10-31 23:04:55 27 4
gpt4 key购买 nike

所以我花了很多时间编写一个脚本来执行特定任务,当我在本地机器上测试它时它工作正常,但是当我将它上传到我的主机时它给我这个错误

Fatal error: Cannot use object of type DOMNodeList as array

这是脚本的示例

$xml = new DOMDocument();
$xml->loadHTML($html);

$xpath = new DOMXPath($xml);
$table =$xpath->query("//*[@style='background: #aaaaaa']")->item(0);



$rows = $table->getElementsByTagName("tr");

foreach ($rows as $row) {
if($row->getAttribute('align') === 'center') {
$cells = $row -> getElementsByTagName('td');

// I GET THE ERROR FROM THIS LINE
$add = mysql_escape_string(utf8_decode($cells[0]->nodeValue));

Some logic

}

就像我说的,它在我的本地机器上运行良好,但在我的主机上运行它时出现错误

我使用这段代码来获取加载的扩展,因为我认为问题可能出自那里

print_r(get_loaded_extensions());

这是我机器的结果

Array
(
[0] => Core
[1] => bcmath
[2] => calendar
[3] => ctype
[4] => date
[5] => ereg
[6] => filter
[7] => ftp
[8] => hash
[9] => iconv
[10] => json
[11] => mcrypt
[12] => SPL
[13] => odbc
[14] => pcre
[15] => Reflection
[16] => session
[17] => standard
[18] => mysqlnd
[19] => tokenizer
[20] => zip
[21] => zlib
[22] => libxml
[23] => dom
[24] => PDO
[25] => bz2
[26] => SimpleXML
[27] => wddx
[28] => xml
[29] => xmlreader
[30] => xmlwriter
[31] => apache2handler
[32] => openssl
[33] => curl
[34] => mbstring
[35] => exif
[36] => gd
[37] => gettext
[38] => intl
[39] => mysql
[40] => mysqli
[41] => Phar
[42] => pdo_mysql
[43] => pdo_sqlite
[44] => soap
[45] => sockets
[46] => sqlite3
[47] => xmlrpc
[48] => xsl
[49] => mhash
)

来 self 的主机

Array
(
[0] => Core
[1] => date
[2] => ereg
[3] => libxml
[4] => openssl
[5] => pcre
[6] => sqlite3
[7] => zlib
[8] => bcmath
[9] => bz2
[10] => calendar
[11] => ctype
[12] => curl
[13] => dom
[14] => hash
[15] => fileinfo
[16] => filter
[17] => ftp
[18] => gd
[19] => gettext
[20] => SPL
[21] => iconv
[22] => session
[23] => intl
[24] => json
[25] => mbstring
[26] => mcrypt
[27] => standard
[28] => mysql
[29] => mysqli
[30] => pgsql
[31] => mysqlnd
[32] => Phar
[33] => posix
[34] => pspell
[35] => Reflection
[36] => imap
[37] => SimpleXML
[38] => soap
[39] => sockets
[40] => exif
[41] => tidy
[42] => tokenizer
[43] => xml
[44] => xmlreader
[45] => xmlrpc
[46] => xmlwriter
[47] => xsl
[48] => zip
[49] => cgi-fcgi
[50] => PDO
[51] => pdo_sqlite
[52] => pdo_mysql
[53] => ionCube Loader
[54] => Zend Guard Loader
)

不知道为什么会报错

最佳答案

getElementsByTagName()返回 DOMNodeList , 它实现了 ArrayAccess as of PHP 5.6.3 .这就是允许您通过 $cells[0] 访问节点的原因。

在以前的版本中,您需要使用 DOMNodeList 的 item()访问特定索引的方法,例如$cells->item(0).

关于php - fatal error : Cannot use object of type DOMNodeList as array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35845819/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com