D
D
Dmitry2014-03-14 17:13:08
PHP
Dmitry, 2014-03-14 17:13:08

Why does the code return a value only once?

Why does it return a value only once? And give an assessment to the code - where is something missing or something superfluous? Perhaps it could have been written more simply?

<?php
class parser {
    protected $url;
    protected $host;
    protected $content;
    protected $link;
    protected $parsed;
    protected $gotHost;

    public function __construct($url) {
        $this->url = $url;
    }

    public function parseIt() {
        $content = file_get_contents($this->url);
        preg_match("~<img src=\"(.*)\"~Uis", $content, $parsed);
        $link = $parsed[1];
        return $link;
    }

    public function getHost() {
        $gotHost = parse_url($this->url, PHP_URL_HOST);
        return $gotHost;
    }
}

$parser = new parser('http://vk.com/id1');
echo $parser->parseIt();
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-03-14
@another_dream

As I understand it, you wanted praseIt to return everything that it found. Then you need to use preg_match_all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question