Home page >> Related Tutorials >>Body

PHP Tutorial - Obtaining TDK Contents of Meta Tags on Website Pages

Author: A little Jack    Time: 2022-09-07 17:23:19    Browse: 2168   

Dunga: Continued from the previous article PHP Tutorial Get Website ico File Address Later, let's share how to get the website tdk (title, keyword, description) and other content. Baidu Yisou also has many methods, but they are all different. It's better to write an interface with someone else's interface, once and for all, because you don't know when someone else's interface will fail. Let's take a look at how to get the website TDK together.

1、 PHP built-in method

 $array = get_meta_tags(" https://www.lkba.cn/ "); var_dump($array);

Use the get_meta_tags method that comes with it to quickly obtain, but you cannot obtain the title. However, keywords, descriptions and other meta values can also be obtained. You can try it yourself. The get_meta_tags method defaults to utf-8 encoding. If encountering gbk and gb2312 encoding, garbled code will appear. You need to use the mb_convert_encoding method to convert the encoding. You can also add the following code to the php file:

 header("content-type:text/html; charset=gb2312");

The prerequisite is to know the default page code.

2、 Grab web pages, regular matching

The method here is to directly obtain the entire page, and then regularly match the rules of the tdk to obtain the content.

Needless to say, if the file_get_contents fails to get the page, the curl method is used to get it.

After getting the web page, you can start to match the meta tag. Since there are several different ways to write the meta tag, it is also different to get it. Here we share a more comprehensive method.

PHP function:

Hello, you need to log in to our account to view the hidden content, please first Sign in To view!


Text label: PHP   Get TDK   Get meta  
 A little Jack

A little Jack https://lkba.cn

The blogger focuses on Z-Blog website construction, website optimization, computer troubleshooting, reinstallation, optimization, maintenance system, etc., QQ/WX: 2126245521 (please specify the purpose)

Related articles

Previous:

Next:

No comment for this article - Welcome

 Please fill in the verification code

Processed : 0.051 SQL : 14