dsa45664 2013-08-04 18:38
浏览 39

使用html dom解析器获取所有区域的标题

Trying to get all the title="" vales of an area's but its only picking the the main title of the page. Sample area html:

<area shape="poly" title="Orkney" href="orkney" coords="" />

The page has lots of these and i'm trying to get all the title names My PHP:

function getTextBetweenTags($string, $tagname) {
    // Create DOM from string
    $html = str_get_html($string);

    $titles = array();
    // Find all tags 
    foreach($html->find($tagname) as $element) {
        $titles[] = $element->plaintext;
    }

    return $titles;
}


print_r(getTextBetweenTags($url, 'title'));

All i get is the title of the page, is this the correct way, or can it not be done, thanks for any help :)

  • 写回答

2条回答 默认 最新

  • doupao3662 2013-08-04 18:43
    关注

    call the method like this:

    print_r(getTextBetweenTags($url, 'area'));
    

    since you're searching for area tags. The title is an argument. See this documentation for an idea how to do it.

    评论

报告相同问题?