Conditions | 5 |
Paths | 5 |
Total Lines | 24 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
9 | public function fetch($url) |
||
10 | { |
||
11 | $html = $this->curl_get_contents($url); |
||
12 | |||
13 | /** |
||
14 | * parsing starts here:. |
||
15 | */ |
||
16 | $doc = new DOMDocument(); |
||
17 | @$doc->loadHTML($html); |
||
|
|||
18 | |||
19 | $tags = $doc->getElementsByTagName('meta'); |
||
20 | $metadata = []; |
||
21 | |||
22 | foreach ($tags as $tag) { |
||
23 | if ($tag->hasAttribute('property') && strpos($tag->getAttribute('property'), 'og:') === 0) { |
||
24 | $key = strtr(substr($tag->getAttribute('property'), 3), '-', '_'); |
||
25 | $value = $tag->getAttribute('content'); |
||
26 | } |
||
27 | if (!empty($key)) { |
||
28 | $metadata[$key] = $value; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | return $metadata; |
||
33 | } |
||
50 |
If you suppress an error, we recommend checking for the error condition explicitly: