登录  /  注册

php解析html dom节点树

php中文网
发布: 2016-08-08 09:32:22
原创
1458人浏览过

不得不感叹用dom直接解析html dom树的灵活和强大,因为基本的html元素就是那么几种常见的,再加上id属性或者class属性之类的。。

在解析html文件时,完全可以用正则中脱离出来,毕竟HTML文件中存在大量相似的模式,而且代码看上去功能比较显而易见,当然正则是非常强大的,应用的领域也更广。。

代码如下:

<?php //关闭载入包含js时的警告提示
error_reporting(E_ERROR | E_PARSE);
class DomTree
{
    //DOM句柄
    private $doc=null;

    //保存基本解释
    private $basic_meaning=array();

    //保存英汉双解
    private $en_or_ch=array();

    //保存英英释义
    private $en_to_en=array();

    //保存例句
    private $example=array();

    //保存常用句型
    private $sentences=array();

    //保存词汇表
    private $glossary=array();

    //保存经典名人名言
    private $auth=array();

    //保存常见错误用法
    private $use_in_wrong = array();

    //保存近义词
    private $approximate_words = array();

    //保存百科解释
    private $baike_trans = array();


    public function __construct($source)
    {
        $this->doc = new DomDocument();

        //判断$source类型
        if(is_file($source))
        {
            file_exists($source)?$this-&gt;doc-&gt;loadHTMLFile($source):die("文件不存在");
        }
        else if(is_string($source))
        {
           empty($source)?die("传入的字符串不能为空"):$this-&gt;doc-&gt;loadHTML($source);
        }
        else
        {
            preg_match('#^(http|ftp)://#i', $source)?$this-&gt;doc-&gt;loadHTML(file_get_contents($source)):die("不支持的资源类型");
        }

        //获取div元素列表
        $div_list = $this-&gt;doc-&gt;getElementsByTagName("div");
        $div_list_len = $div_list-&gt;length;

        for($i=0; $iitem($i)-&gt;hasAttribute("class"))
            {
                switch(trim($div_list-&gt;item($i)-&gt;getAttribute ("class")))
                {
                    case "basic clearfix":
                        $this-&gt;getBasicMeans($div_list-&gt;item($i));
                        break;

                    case "layout dual":
                        $this-&gt;getEnOrCh($div_list-&gt;item($i));
                        break;

                    case "layout en":
                        $this-&gt;getEnToEn($div_list-&gt;item($i));
                        break;

                    case "layout sort":
                        $this-&gt;getExample($div_list-&gt;item($i));
                        break;

                    case "layout patt":
                        $this-&gt;normalSentence($div_list-&gt;item($i));
                        break;

                    case "layout coll":
                        $this-&gt;getGlossary($div_list-&gt;item($i));
                        break;

                    case "layout auth":
                        $this-&gt;getAuth($div_list-&gt;item($i));
                        break;

                    case "layout comn":
                        $this-&gt;useInWrong($div_list-&gt;item($i));
                        break;

                    case "layout nfw":
                        $this-&gt;getApproximateWords($div_list-&gt;item($i));
                        break;

                    case "layout baike";
                        $this-&gt;getBaike($div_list-&gt;item($i));
                        break;
                }
            }
        }

    }

    //获取基本解释
    private function getBasicMeans($basic_div)
    {
        $li_list = $basic_div-&gt;getElementsByTagName("li");
        $li_list_len = $li_list-&gt;length;
        for($i=0; $iitem($i);
            if($item-&gt;hasAttribute("style"))
            {
                continue;
            }
            else
            {
                $strong_list  = $item-&gt;getElementsByTagName("strong");
                $strong_list_len = $strong_list-&gt;length;
                for($j=0; $jbasic_meaning[]=$strong_list-&gt;item($j)-&gt;nodeValue;
                }
            }
        }
    }

    //获取英汉双解释义
    private function getEnOrCh($div_elem)
    {
        $li_list = $div_elem-&gt;getElementsByTagName("li");
        $li_list_len = $li_list-&gt;length;
        for($i=0; $ien_or_ch[]=$li_list-&gt;item($i)-&gt;nodeValue;

        }
    }

    //获取英英释义
    private function getEnToEn($div_elem)
    {
        $li_list = $div_elem-&gt;getElementsByTagName("li");
        $li_list_len = $li_list-&gt;length;
        for($i=0; $ien_to_en[]= $this-&gt;strip_Empty($li_list-&gt;item($i)-&gt;nodeValue);
        }
    }
    //格式化操作
    private function strip_Empty($string)
    {
        if(is_string($string))
        {
            return preg_replace('#\s{2,}#', ' ', $string);
        }
    }

    //获取例句
    private function getExample($div_elem)
    {
        if($div_elem-&gt;hasChildNodes())
        {
            $ol_list = $div_elem-&gt;getElementsByTagName("ol");
            $ol_list_len = $ol_list-&gt;length;
            for($i=0; $iitem($i)-&gt;getElementsByTagName("li");
               $li_list_len = $li_list-&gt;length;
               for($j=0; $jexample[] = $this-&gt;strip_Empty($li_list-&gt;item($j)-&gt;nodeValue);
               }
            }
        }
    }

    //常见句型
    private function normalSentence($div_elem)
    {
        $ol_list = $div_elem-&gt;getElementsByTagName("ol");
        $ol_list_len = $ol_list-&gt;length;
        for($i=0; $iitem($i)-&gt;getElementsByTagName("li");
            $li_list_len = $li_list-&gt;length;
            for($j=0; $jsentences[]=$this-&gt;strip_Empty($li_list-&gt;item($j)-&gt;nodeValue);
            }

        }
    }

    //常见词汇
    private function getGlossary($div_elem)
    {
        $ul_list = $div_elem-&gt;getElementsByTagName("ul");
        $ul_list_len = $ul_list-&gt;length;
        for($i=0; $iitem($i)-&gt;getElementsByTagName("li");
            $li_list_len = $li_list-&gt;length;
            for($j=0; $jglossary[]=$this-&gt;strip_Empty($li_list-&gt;item($j)-&gt;nodeValue);
            }

        }
    }

    //获取名人名言
    private function getAuth($div_elem)
    {
        $ul_list = $div_elem-&gt;getElementsByTagName("ul");
        $ul_list_len = $ul_list-&gt;length;
        for($i=0; $iitem($i)-&gt;getElementsByTagName("li");
            $li_list_len = $li_list-&gt;length;
            for($j=0; $jauth[]=$this-&gt;strip_Empty($li_list-&gt;item($j)-&gt;nodeValue);
            }

        }
    }

    //获取常见错误用法
    private function useInWrong($div_elem)
    {
        $ol_list = $div_elem-&gt;getElementsByTagName("ol");
        $ol_list_len = $ol_list-&gt;length;
        for($i=0; $iitem($i)-&gt;getElementsByTagName("li");
            $li_list_len = $li_list-&gt;length;
            for($j=0; $juse_in_wrong[]=$this-&gt;strip_Empty($li_list-&gt;item($j)-&gt;nodeValue);
            }

        }
    }

    //获取近义词
    private function getApproximateWords($div_elem)
    {
        $ul_list = $div_elem-&gt;getElementsByTagName("ul");
        $ul_list_len = $ul_list-&gt;length;
        for($i=0; $iitem($i)-&gt;getElementsByTagName("li");
            $li_list_len = $li_list-&gt;length;
            for($j=0; $jitem($j)-&gt;getElementsByTagName("a");
                $a_list_len = $a_list-&gt;length;
                for($k=0; $kapproximate_words[]=$a_list-&gt;item($k)-&gt;nodeValue;
                }
            }

        }
    }

    //获取百科解释
    private function getBaike($div_elem)
    {
        $ul_list = $div_elem-&gt;getElementsByTagName("ul");
        $ul_list_len = $ul_list-&gt;length;
        for($i=0; $iitem($i)-&gt;getElementsByTagName("li");
            $li_list_len = $li_list-&gt;length;
            for($j=0; $jbaike_trans[]=$li_list-&gt;item($j)-&gt;nodeValue;
            }

        }
    }

    //接口:  返回基本释义
    public function getBasicMeaning()
    {
        if(!empty($this-&gt;basic_meaning))
        {
            return $this-&gt;basic_meaning;
        }
    }

    //接口: 返回英汉双解
    public function getEnOrChMeaning()
    {
        if(!empty($this-&gt;en_or_ch))
        {
            return $this-&gt;en_or_ch;
        }
    }

    //接口:  返回英英释义
    public function getEnToEnMeaning()
    {
        if(!empty($this-&gt;en_to_en))
        {
            return $this-&gt;en_to_en;
        }
    }

     //接口:  返回例句
    public function getExampleMeaning()
    {
        if(!empty($this-&gt;example))
        {
            return $this-&gt;example;
        }
    }
    //接口:  返回常用句型
    public function getNormalSentenceMeaning()
    {
        if(!empty($this-&gt;sentences))
        {
            return $this-&gt;sentences;
        }
    }

    //接口:  返回词汇表
    public function getGlossaryMeaning()
    {
        if(!empty($this-&gt;glossary))
        {
            return $this-&gt;glossary;
        }
    }

    //接口:  返回名人名言
    public function getAuthMeaning()
    {
        if(!empty($this-&gt;auth))
        {
            return $this-&gt;auth;
        }
    }

    //接口:  返回常见错误用法
    public function getUseInWrongMeaning()
    {
        if(!empty($this-&gt;use_in_wrong))
        {
            return $this-&gt;use_in_wrong;
        }
    }

    //接口:  获取近义词
    public function getApproximateWordsMeaning()
    {
        if(!empty($this-&gt;approximate_words))
        {
            return $this-&gt;approximate_words;
        }
    }

    //接口: 获取百度百科的解释
    public function getBaikeMeaning()
    {
        if(!empty($this-&gt;baike_trans))
        {
            return $this-&gt;baike_trans;
        }
    }

    //返回所有的翻译
    public function getAllMeaning()
    {
        $all_meaning = array();
        $all_meaning['basic_meaning'] = $this-&gt;getBasicMeaning();
        $all_meaning['en_or_ch'] = $this-&gt;getEnOrChMeaning();
        $all_meaning['en_to_en'] = $this-&gt;getEnToEnMeaning();
        $all_meaning['example']=$this-&gt;getExampleMeaning();
        $all_meaning['normal_sentence'] = $this-&gt;getNormalSentenceMeaning();
        $all_meaning['glossary_sentence'] = $this-&gt;getGlossaryMeaning();
        $all_meaning['auth_sentence'] = $this-&gt;getAuthMeaning();
        $all_meaning['wrong_use'] = $this-&gt;getUseInWrongMeaning();
        $all_meaning['approximate_words'] = $this-&gt;getApproximateWordsMeaning();
        $all_meaning['baike_meaning'] = $this-&gt;getBaikeMeaning();
        return $all_meaning;
    }
}

$dom = new DomTree("./com.html");

$trans = $dom-&gt;getAllMeaning();
echo "<pre class="brush:php;toolbar:false">";
print_r($trans);
?&gt;
登录后复制

结果如下:

Array
(
    [basic_meaning] =&gt; Array
        (
            [0] =&gt; 单词;消息;话语;诺言
            [1] =&gt; 用词语表达
        )

    [en_or_ch] =&gt; Array
        (
            [0] =&gt; [C] 字,词 the smallest unit of spoken language which has meaning and can stand alone
            [1] =&gt; [C] (说的)话,话语,言语 anything said; remark or statement
            [2] =&gt; [S] 消息,信息; 谣言 piece of news; message; rumour
            [3] =&gt; [S] 口令,号令; 命令 spoken command or signal
            [4] =&gt; [S] 诺言,保证 a promise
            [5] =&gt; vt. 用词语表达; 选用 express (sth) in particular words; phrase sth
        )

    [en_to_en] =&gt; Array
        (
            [0] =&gt; a unit of language that native speakers can identify; "words are the blocks from which sentences are made" "he hardly said ten words all morning" 
            [1] =&gt; a brief statement; "he didn't say a word about it" 
            [2] =&gt; information about recent and important events; "they awaited news of the outcome" 
            [3] =&gt; a verbal command for action; "when I give the word, charge!" 
            [4] =&gt; an exchange of views on some topic; "we had a good discussion" "we had a word or two about it" 
            [5] =&gt; a promise; "he gave his word" 
            [6] =&gt; a word is a string of bits stored in computer memory; "large computers use words up to 64 bits long" 
            [7] =&gt; the divine word of God; the second person in the Trinity (incarnate in Jesus) 
            [8] =&gt; a secret word or phrase known only to a restricted group; "he forgot the password" 
            [9] =&gt; the sacred writings of the Christian religions; "he went to carry the Word to the heathen" 
            [10] =&gt; put into words or an expression; "He formulated his concerns to the board of trustees" 
        )

    [example] =&gt; Array
        (
            [0] =&gt; Could we have a word before you go to the meeting? 你去开会之前,咱们能私下说句话吗?
            [1] =&gt; My friend sent word that he was well. 我朋友捎来口信说他很好。
        )

    [normal_sentence] =&gt; Array
        (
            [0] =&gt;  What does this word mean? 这个词是什么意思? 
            [1] =&gt;  I couldn't look up the spelling of the word, as I hadn't a dictionary at hand. 我没法查这个词的拼写,因为我手边没有词典。 
            [2] =&gt;  Many English words are derived from Latin. 许多英文单词源于拉丁文。 
            [3] =&gt;  All the words beside the central idea should be crossed out. 凡偏离中心思想的词语都应通通删掉。 
            [4] =&gt;  The editor eliminated slang words from the essay. 编辑将俚语从这篇文章中剔除。 
            [5] =&gt;  These words can't be staled by repetition. 这些词语不会因为经常使用而变成陈词滥调。 
            [6] =&gt;  He gave me his visiting card, with a few words in pencil. 他把他的名片给我,上面有几个铅笔字。 
            [7] =&gt;  I don't believe a word of his story. 他说的这件事我一句话都不相信。 
            [8] =&gt;  At the press conference, the reporters copied down every word spoken by the prime minister. 在新闻发布会上,记者们逐字记下了首相的讲话。 
            [9] =&gt;  Tell me what happened in your words. 用你自己的话把发生的事告诉我。 
            [10] =&gt;  Deeds are better than words when people are in need of help. 当别人需要帮助时,行动胜于语言。 
            [11] =&gt;  I would like a word with you. 我想和你谈谈。 
            [12] =&gt;  After a word with the colonel he went away . 他和上校简单谈过之后就走了。 
            [13] =&gt;  There's been no word from her for weeks. 已经有好几个星期没有她的音信了。 
            [14] =&gt;  Word came that I was needed at home. 有信儿来说家里需要我。 
            [15] =&gt;  Word has come that meeting will be held on Tuesday. 通知已到,星期二开会。 
            [16] =&gt;  Word is that the election will be held in June. 有消息说选举将在六月份举行。 
            [17] =&gt;  Word is that he's left the country. 据说他已经离开这个国家了。 
            [18] =&gt;  Word got round that he had resigned. 谣传他已辞职。 
            [19] =&gt;  Stay hidden until I give the word. 我不下令就藏着别动。 
            [20] =&gt;  Their word is law. 他们的命令必须服从。 
            [21] =&gt;  He gave the word and they let him in. 他说出了口令,他们让他进去了。 
            [22] =&gt;  The word now is “freedom”. 现在的口号是“自由”。 
            [23] =&gt;  I give you my word I'll go. 我向你保证,我会去的。 
            [24] =&gt;  Stand by your word. 要守信用。 
            [25] =&gt;  Hear The Word of God . 听宣讲《圣经》。 
            [26] =&gt;  Be careful how you word your answer. 回答时要斟酌字句。 
            [27] =&gt;  She worded the explanation well. 她的解释措辞得体。 
            [28] =&gt;  The advice wasn't very tactfully worded. 这份通知措辞不太得体。 
            [29] =&gt;  The suggestion might be worded more politely. 那项建议的措辞可以更婉转些。 
            [30] =&gt;  This is a carefully worded contract. 这是一份措辞严谨的合同。 
        )

    [glossary_sentence] =&gt; Array
        (
            [0] =&gt; address a few words 讲几句话
            [1] =&gt; await word from sb 等待某人的消息
            [2] =&gt; break one's words 食言
            [3] =&gt; breathe a word 走漏消息
            [4] =&gt; bring word 带来消息
            [5] =&gt; choose a word 选择词
            [6] =&gt; coin a word 杜撰一个词
            [7] =&gt; cook up words 造新词
            [8] =&gt; cross out a word 划掉一个词
            [9] =&gt; cut out many words 删掉许多词
            [10] =&gt; digest a word 消化一个词
            [11] =&gt; doubt sb's words 怀疑某人的话
            [12] =&gt; drink in all the words 吸收所有的词语
            [13] =&gt; eat one's words 收回前言,认错,道歉
            [14] =&gt; exchange angry words 发生口角
            [15] =&gt; find words 找出言语(来表达)
            [16] =&gt; gain the good word of 博得…的赞扬
            [17] =&gt; get word 得到消息
            [18] =&gt; get a word 插嘴
            [19] =&gt; give one's word 保证,允许
            [20] =&gt; give the word 发出命令
            [21] =&gt; have words together 争吵
            [22] =&gt; have words with sb 与某人吵嘴
            [23] =&gt; have a word with sb 同某人谈一谈
            [24] =&gt; hunt up a word 查一个词
            [25] =&gt; keep one's word 信守诺言
            [26] =&gt; leave word 留言
            [27] =&gt; leave out a word 省略一个词,丢掉一个词
            [28] =&gt; look up a word (在词典里)查一个词
            [29] =&gt; memorize words 记单词
            [30] =&gt; play on words 玩弄字眼
            [31] =&gt; pronounce a word 读一个词
            [32] =&gt; put in words for 为…说几句话
            [33] =&gt; put the words into sb's mouth 教某人怎么讲
            [34] =&gt; quote a word 引用一个词
            [35] =&gt; receive word of 收到…消息
            [36] =&gt; regret one's words 为说过的话而后悔
            [37] =&gt; respect one's word 遵守自己许下的诺言
            [38] =&gt; say a word 说句话,进一步,走漏消息
            [39] =&gt; say a few words 说几句话
            [40] =&gt; say a good word for sb 为某人说好话
            [41] =&gt; send sb a word 给某人捎个信儿
            [42] =&gt; spell a word 拼写一个词
            [43] =&gt; stress the word 重读那个词
            [44] =&gt; take back one's word 收回自己的话
            [45] =&gt; take sb's word for it 相信了某人的话
            [46] =&gt; understand a word 理解某个词的意思
            [47] =&gt; use words 用词
            [48] =&gt; waste one's words 白费口舌
            [49] =&gt; weigh words 斟酌词句
            [50] =&gt; write a word 写一个词
            [51] =&gt; advance word 事先传出的消息
            [52] =&gt; angry words 气话
            [53] =&gt; beautiful words 优美的言辞
            [54] =&gt; big words 大话
            [55] =&gt; borrowed word 外来词
            [56] =&gt; broken words 断断续续的话
            [57] =&gt; burning words 热情洋溢的话
            [58] =&gt; choice words 精选的词句
            [59] =&gt; colorful words 丰富的言辞
            [60] =&gt; cross words 气话
            [61] =&gt; empty words 空洞的话,无意义的话
            [62] =&gt; everyday word 日常用语
            [63] =&gt; farewell words 送别词
            [64] =&gt; fighting words 容易引起争论的话,挑战性的话
            [65] =&gt; foreign word 外来词
            [66] =&gt; hard words 愤怒的话,激烈的话
            [67] =&gt; heated word 激烈的言词,争吵时使用的话
            [68] =&gt; high words 愤怒的话,激烈的话
            [69] =&gt; hollow words 虚假的言语
            [70] =&gt; honeyed words 甜言蜜语
            [71] =&gt; hot words 激烈的言词,争吵时使用的话
            [72] =&gt; household word 家喻户晓的词
            [73] =&gt; irresponsible words 不负责任的话
            [74] =&gt; key words 关键的字眼
            [75] =&gt; last words 临终遗言
            [76] =&gt; living words 现代语
            [77] =&gt; meaningful words 意味深长的言语
            [78] =&gt; meaningless words 无意义的话
            [79] =&gt; misspelled word 拼错的词
            [80] =&gt; native word 本国词,本地词
            [81] =&gt; pleasant words 动听的语言
            [82] =&gt; regional word 方言
            [83] =&gt; scientific word 科学用语
            [84] =&gt; semi-technical words 半科技词
            [85] =&gt; sharp words 愤怒的话,激烈的话
            [86] =&gt; simple word 简单的词
            [87] =&gt; sincere words 真诚的话
            [88] =&gt; small word 小词
            [89] =&gt; spoken words 口头语
            [90] =&gt; suggestive words 含蓄的话
            [91] =&gt; sweet words 甜言蜜语
            [92] =&gt; tearful parting words 伤感的离别之言
            [93] =&gt; the latest word 最新消息,最后消息
            [94] =&gt; uncleanly words 下流话
            [95] =&gt; unfamiliar word 生词
            [96] =&gt; unusual word 冷僻词
            [97] =&gt; warm words 忿怒的话,激烈的话
            [98] =&gt; written words 书面语
            [99] =&gt; wrong words 错词
            [100] =&gt; dictionary word 词典里出现的词
            [101] =&gt; English words 英语单词
            [102] =&gt; law word 法律用语
            [103] =&gt; newspaper word 新闻用语
            [104] =&gt; slang word 俚语
            [105] =&gt; at a word 立即,立刻
            [106] =&gt; in a word 简言之,总之
            [107] =&gt; in one's own words 用自己的话说
            [108] =&gt; in other words 换言之
            [109] =&gt; upon my word 的确,真的
            [110] =&gt; without a word 一声没吭
            [111] =&gt; word in heavy type 黑体字
            [112] =&gt; words in season 时宜的话
            [113] =&gt; words of comfort 安慰的话
            [114] =&gt; words of command 命令
            [115] =&gt; words of complaint 怨言
            [116] =&gt; the W- of God 圣经
            [117] =&gt; words of praise 表扬的话
            [118] =&gt; word of six letters 六个字母的词
            [119] =&gt; words of thanks 感谢的话
            [120] =&gt; word the explanation 解释
            [121] =&gt; word accurately 准确地用言语表达
            [122] =&gt; word crudely 简单地用词语〔语言〕表达
            [123] =&gt; word felicitously 恰当地用言语表达
            [124] =&gt; word intelligibly 清楚地用语言表达
            [125] =&gt; word positively 明确地用词语表达
            [126] =&gt; word vaguely 含糊地表达
            [127] =&gt; word well 措辞得体
        )

    [auth_sentence] =&gt; Array
        (
            [0] =&gt;  Rome shall perishswrite that word In the blood that she has spilt. 出自:W. Cowper 
            [1] =&gt;  We have striven..to draw some word from her; but she..answers nothing. 出自:G. P. R. James 
            [2] =&gt;  To use his own words, he was in a cleft stick. 出自:H. Conway 
            [3] =&gt;  Actions speak louder than words. 出自:Proverb 
            [4] =&gt;  He words me, girls, he words me, that I should not Be noble to myself. 出自:Anthony Cleopatra,Shakespeare 
        )

    [wrong_use] =&gt; Array
        (
            [0] =&gt; 我要跟他说句话。 误 I should like to have word with him. 正 I should like to have a word with him. 
            [1] =&gt; 他们听到消息说足球比赛将在今晚电视实况转播。 误 They had a word that the football match would be televised live this evening. 正 They had word that the football match would be televised live this evening. 析 have word是“听到消息〔新闻〕”的意思,“说句话”是have a word。 
            [2] =&gt; 对逐词背课文,我感到厌倦。 误 I was tired of reciting the texts word after word. 正 I was tired of reciting the texts word for word. 析 “一字不变地,逐字(背诵或翻译)”是word for word,不是word after word。 
            [3] =&gt; 我说了什么错话吗? 误 Have I said any wrong words? 正 Have I said anything wrong? 析 误句语法上没有错,但不符合英语习惯。 
            [4] =&gt; 他不遵守诺言。 误 He broke his words. 正 He broke his word. 析 break one's word意为“不遵守诺言”, word在此短语中不用复数形式。 
            [5] =&gt; 我刚得知他到达的消息。 误 I have just received the word of his arrival. 正 I have just received word of his arrival. 
            [6] =&gt; 有消息传来说我们的篮球队赢了这场比赛。 误 The word came that our basketball team had won the match. 正 Word came that our basketball team had won the match. 析 作“消息”“信息”解时, word前不加冠词。 
            [7] =&gt; 他大约是30年前开始当教师的,换句话说,他当教师已经有30年了。 误 He began to work as a teacher some thirty years ago, in another word, he has been a teacher for thirty years. 正 He began to work as a teacher some thirty years ago, in other words, he has been a teacher for thirty years. 析 in other words是固定短语,意为“换句话说”。 
            [8] =&gt; 他带信给我说怀特先生不久将动身去美国。 误 He carried me words that Mr.White would soon leave for America. 正 He carried me word that Mr. White would soon leave for America. 析 word作“消息”“信”解时,是不可数名词,其后不可加s。 
            [9] =&gt; 今晨我们争吵了。 误 We had a word this morning. 正 We had words this morning. 
            [10] =&gt; 他们曾为鸡毛蒜皮的小事同邻居吵过嘴。 误 They had word with their neighbour over some trifles. 正 They had words with their neighbours over some trifles. 析 表示“同某人发生口角”时,用have words with sb, words用复数形式。 
            [11] =&gt; 他说的大话使我们都感到惊讶。 误 His big word surprised us all. 正 His big words surprised us all. 
            [12] =&gt; 我们绝不收回前言。 误 We should on no account eat our word. 正 We should on no account eat our words. 析 习语big words, eat one's words中, words词尾的s不可省。 
        )

    [approximate_words] =&gt; Array
        (
            [0] =&gt; account
            [1] =&gt; advice
            [2] =&gt; chat
            [3] =&gt; communication
            [4] =&gt; declaration
            [5] =&gt; edict
            [6] =&gt; expression
            [7] =&gt; message
            [8] =&gt; notice
            [9] =&gt; order
            [10] =&gt; password
            [11] =&gt; promise
            [12] =&gt; remark
            [13] =&gt; term
            [14] =&gt; couch
            [15] =&gt; explain
            [16] =&gt; express
            [17] =&gt; phrase
            [18] =&gt; put
            [19] =&gt; say
            [20] =&gt; write
        )

    [baike_meaning] =&gt; Array
        (
            [0] =&gt; word:Microsoft Word,属于办公软件,人们日常生活都有可能接触到他,对他并不陌生。 简介 wordMicrosoft Word是微软公司的一个文字处理器应用程序。它最初是由Richard Bro…
        )

)
登录后复制

以上就介绍了php解析html dom节点树,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号