解析错误:语法错误,Crawler代码中出现意外的T_VARIABLE错误

时间:2012-07-14 13:45:22

标签: php

我已经搜索过这个答案,但无法找到它。我收到错误消息,“解析错误:语法错误,意外T_VARIABLE”并认为它与第30行中列出的“a”有关。任何想法如何使此代码正确?

<?php
class Crawler {
    protected $markup = ”;
    public function __construct($uri) {
        $this->markup = $this->getMarkup($uri);
    }

    public function getMarkup($uri) {
        return file_get_contents($uri);
    }

    public function get($type) {
        $method = array($this,”_get_”.$type);
        if (method_exists($this,$method[1]))
            return call_user_func($method);
        return false;
    }

    protected function _get_images() {
        if (!empty($this->markup)){
            preg_match_all("/<img([^>]+)\/>/i", $this->markup, $images);
            return !empty($images[1]) ? $images[1] : FALSE;
        }
    }

    protected function _get_links() {
        if (!empty($this->markup)){
            preg_match_all("/<a([^>]+)\>(.*?)\<\/a\>/i", $this->markup, $links);
            return !empty($links[1]) ? $links[1] : FALSE;
        }
    }
}
a 
$crawl = new Crawler("http://www.facebook.com");
$images = $crawl->get("images");
$links = $crawl->get("links");
?>

2 个答案:

答案 0 :(得分:0)

您可以尝试在第30行;之后加a

答案 1 :(得分:0)

删除a,并使用直引号"代替当前的引号。

相关问题