tags:

views:

34

answers:

2

Hi guys,

I've been trying today all day to figure this out and I have no idea.

What I want: Get the title and meta description of any kind of website.

Save this info to utf table in mysql.

What the problem is? Different sites have different charsets which results in that some have chinese, some contain umlauts (german), then we have russian and so on..

I've tried preg_match which works for some while not for others, i've tried DOMdocument which is the same as preg_match.

Is there any class available that will do this?

Hope someone can help, thanks.

A: 
$data = file_get_contents( $url );
if( preg_match( '#title>([^<]+?)</title#', $data, $match ) ) {
    $result['title'] = $match[1];
}
if( preg_match( '#name="description"[^>]+?content=('|")([^"']+?)#i', $data, $match ) ) {
    $result['description'] = $match[2];
}

not tested! just wrote it down quickly - print_r the match's to see what exactly they match etc.

set your mysql table to latin1 - that should be fine with all kinds of languages. - i never took care of it because it works 99% of the time.

Tobias
Doesn't work, the regexp..Also tried with latin1 charset, it also doesn't work.
Geteburg
define "doesnt work"
Tobias
A: 

Use Curl and explode function and you will be able to do it easily.

hey
I do use Curl to get the pages source. But then the problem is saving this info to table.To give an example, get me the title of this websites and save it to table:http://www.baidu.com/http://www.yandex.ru/Amongst others..
Geteburg