Hello. Please tell me, here is the task to get the value of the title tag from another site, the site is not known in advance, it can be absolutely anything. How i do it now
$dom = new DOMDocument(); $tag = 'title'; @$dom->loadHTML(@file_get_contents('http://site.com/')); if ($dom->getElementsByTagName($tag)->length > 0) $title = $dom->getElementsByTagName($tag)->item(0)->textContent; else $title = '';
But sites on which the windows-1251 encoding gives me the title in this form
Site - Ðåêëàìíîå àãåíòñòâî. Ýôôåêòèâíàÿ ðàñêðóòêà ñàéòîâ
I tried to use the functions mb_convert_encoding () and iconv () with different parameters, but none of them gave the desired result. Please tell me how you can get a readable title where the windows-1251 encoding
file_get_contents()
intoUTF-8
and then load the data into theDOMDocument
. - Visman