How to extract the name of the site?

Possible duplicate:
Best HTML Parsing Techniques

How to extract website title using PHP?

0
source share
3 answers

To create manupulate using HTML, you can use the Document Object Model (this is the recommended way).

If you are looking for a dirty quick fix, this is a pretty simple expression:

$html = file_get_contents('http://example.com'); $matches = preg_match("/<title>([^<]*)<\/title>/im"); echo $matches[1]; 
+5
source

You can get the domain name via $_SERVER['HTTP_HOST'] .

0
source

Take the document using curl , run it through the parser and then use any API that the parser provides to get the title element ( //title will execute if XPath is supported).

0
source

Source: https://habr.com/ru/post/887198/


All Articles