利于XML词库,用PHP处理时出现
Notice: Trying to get property of non-object in C:\apache\htdocs\olword\wordprocess.php Fatal error: Call to a member function getElementsByTagName() on a non-object in C:\apache\htdocs\olword\wordprocess.php
if($type=="update"){
//接收新的单词 $update_word_en=$_REQUEST['enword'];
$update_word_ch=$_REQUEST['chword'];
//查询
$words=$xmldoc->getElementsByTagName("word");
$isEnd=false;
//遍历
for($i=0;$i<$words->length;$i++){
//依次取出单词
$word=$words->item($i);
$word_en=getNodeVal($word,"en");
if($update_word_en==$word_en){
$isEnd=true;
/ /这里出现错误
$parent_word=$word_en->parentNode;
$word_ch=$parent_word->getElementsByTagName("ch")->item(0);
$word_ch->nodeValue=$update_word_ch;
//$word_en->nextSibling->nodeValue=$update_word_ch;这样修改也有问题
//更新文件
$isUpateOk=$xmldoc->save("word.xml");
if( $isUpateOk){ echo "更新成功";
}else echo "更新失败";
}
}
if(!$isEnd){
echo "查无此词"; }}
Notice: Trying to get property of non-object in C:\apache\htdocs\olword\wordprocess.php Fatal error: Call to a member function getElementsByTagName() on a non-object in C:\apache\htdocs\olword\wordprocess.php
if($type=="update"){
//接收新的单词 $update_word_en=$_REQUEST['enword'];
$update_word_ch=$_REQUEST['chword'];
//查询
$words=$xmldoc->getElementsByTagName("word");
$isEnd=false;
//遍历
for($i=0;$i<$words->length;$i++){
//依次取出单词
$word=$words->item($i);
$word_en=getNodeVal($word,"en");
if($update_word_en==$word_en){
$isEnd=true;
/ /这里出现错误
$parent_word=$word_en->parentNode;
$word_ch=$parent_word->getElementsByTagName("ch")->item(0);
$word_ch->nodeValue=$update_word_ch;
//$word_en->nextSibling->nodeValue=$update_word_ch;这样修改也有问题
//更新文件
$isUpateOk=$xmldoc->save("word.xml");
if( $isUpateOk){ echo "更新成功";
}else echo "更新失败";
}
}
if(!$isEnd){
echo "查无此词"; }}
解决方案 »
- Fatal error: Call to undefined function oci_connect() 应该要怎么解决
- 中国服务外包那地发达一点呀
- php session保存时间没有效果?
- PHP中的数字字符串在不同编码下也能乱码?
- 高手进来解释一句话$page.=',';
- 关于php的syslog函数输出日志问题
- 水版看到个算法题,转到这里与大家讨论
- apache已经配好,可就是不解析PHP,总让下载!!
- 用remote.addr取得的本地地址怎么会是127.0.0.1
- 安装PDT插件时,点击confirm后出错
- 请高手帮忙看下我写的判断某个页面是否被百度收录的代码
- PHP include
$type=$_POST["type"];//判断用户的行为
$xmldoc=new DOMDocument();
$xmldoc->load("word.xml"); function getNodeVal(&$myNode,$tagName){
return $myNode->getElementsByTagName($tagName)->item(0)->nodeValue;
}
找到这个错误了,我自定义的函数找到的是一个值,不是一个对象,汗,引用错误了。还是谢谢你了