


How to connect Baidu Wenxin Yiyan API with PHP to obtain random statements and generate blog summary
How to connect PHP to Baidu Wenxin Yiyan API to obtain random sentences and generate blog summaries
With the development of the Internet, blogs have become a way for people to share knowledge and experience important platform. A good blog needs to have an attractive title and exciting content. And generating an attractive blog summary is also key to attracting readers. This article will introduce a method of using PHP to connect to Baidu Wenxin Yiyan API to obtain random sentences and generate blog summaries.
Baidu Wenxin Yiyan is an API service that provides random sentences. It provides a large number of sentences, including philosophy, poetry, movie lines, etc. We can use this API to generate blog summaries and add some literary flavor to the blog.
First, we need to apply for a Baidu developer account, create an application, and obtain the API Key and Secret Key. Then, we can use PHP's cURL library to connect to Baidu Wenxin Yiyan API and obtain random statements.
<?php // 定义API请求地址和参数 $url = 'https://api.lwl12.com/hitokoto/v1?encode=json'; $params = [ 'encode' => 'json', ]; // 拼接请求URL $url .= '&' . http_build_query($params); // 初始化cURL $ch = curl_init(); // 设置请求URL curl_setopt($ch, CURLOPT_URL, $url); // 设置返回结果不直接输出 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 发起请求 $response = curl_exec($ch); // 关闭cURL curl_close($ch); // 解析JSON格式的响应结果 $result = json_decode($response, true); // 获取语句内容 $sentence = $result['hitokoto']; // 输出结果 echo $sentence; ?>
The above code will connect to Baidu Wenxin Yiyan API and obtain random statements. We can place this code in the blog generation process to get different statements.
Next, we can generate a summary of the blog based on the obtained statements. When generating a summary, we can extract the keywords in the sentence and add some text descriptions. The following is a sample code:
<?php // 获取语句 $sentence = '这是一条随机语句'; // 提取关键词 $keywords = ['随机', '语句']; // 加上说明文字 $intro = '本文来自百度文心一言API,'; // 拼接摘要 $summary = $intro . '关键词:' . implode('、', $keywords) . '。' . $sentence; // 输出摘要 echo $summary; ?>
The above code example will generate a blog summary, for example: This article comes from Baidu Wenxin Yiyan API, keywords: random, statement. This is a random statement.
Finally, we integrate the above code into our blog generation process to generate different blog summaries as needed. In this way, our blog will be more attractive and add some literary flavor.
Summary:
This article introduces a method of using PHP to connect to Baidu Wenxin Yiyan API to obtain random statements and generate blog summaries. Obtain random sentences by connecting to the API, and then generate blog summaries according to needs, which can increase the attractiveness and literary sense of the blog. I hope this article can help you improve the quality of your blog and reader experience.
The above is the detailed content of How to connect Baidu Wenxin Yiyan API with PHP to obtain random statements and generate blog summary. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Reasons for an exclamation mark on wifi include incorrect WiFi password, weak WiFi signal, WiFi channel interference, network setting problems, software or hardware problems, etc. Detailed introduction: 1. Wrong WiFi password may be one of the common reasons for the appearance of exclamation marks. When connecting to a WiFi network that requires a password, if the password entered is wrong, the system will prompt that the password is incorrect and an exclamation mark will be displayed on the WiFi icon; 2 . Weak WiFi signal is also one of the common reasons why the exclamation mark appears, such as when it is too far away from the wireless router or blocked by obstacles, etc.

The reason why there is an exclamation mark on the mobile wifi may be that it cannot connect to the Internet, the signal is weak, authentication issues and IP address conflicts, etc. Detailed introduction: 1. Unable to connect to the Internet. If an exclamation mark appears on the Wi-Fi icon, it may be because the mobile phone cannot connect to the Internet. This may be caused by a router disconnection, network failure, or mobile phone settings problem; 2. The signal is weak. If an exclamation mark appears on the Wi-Fi icon, it may be caused by a weak Wi-Fi signal. This may be due to being too far from the router, being blocked by obstacles, or interfering with the signal, etc.

The wifi is connected but there is an exclamation mark, which may be caused by incorrect routing settings. The solution: 1. Check whether the router and broadband line interfaces are loose; 2. Double-click to open the computer's "Control Panel", and then open "Network and Sharing" Center"; 3. Click "Change Adapter Settings", and then select the "Obtain IP address automatically" and "Obtain DNS server address automatically" buttons.

Recently, many friends have asked me what to do when Fliqlo displays exclamation marks. Next, let us learn how to solve the problem of Fliqlo displaying exclamation marks. I hope it can help everyone. 1. Enter the control panel and select the internet option in the control panel, as shown in the figure below. 2. Enter the Internet Properties page, as shown in the figure below. 3. Click the Advanced tab, as shown in the figure below. 4. Also check "Use TLS1.0, 1.1, 1.2" so that you can use Fliqlo normally, as shown in the figure below. The above is the entire content of what the editor brings to you on how to deal with the exclamation mark when Fliqlo displays it. I hope it will be helpful to you.

Reasons and solutions for the exclamation mark on intel wireless ac9560: 1. Caused by software driver problems, you can reinstall the driver directly; 2. Caused by conflicts between software and hardware, you can upgrade the window system; 3. Caused by conflicts between hardware and hardware, You can restart the computer, reinstall specific drivers or replace the wireless network card.

It is a very common problem that the network icon displays an exclamation mark, but many friends do not know how to deal with this problem. Let me share with you how to solve the problem when the win7 computer cannot connect to the network. 1. First, we need to right-click the network icon and select [Network and Sharing Center]. 2. Then we click [Change Adapter Settings]. 3. Click [Local Area Connection]. 4. Then we click [Diagnosis]. 5. Enter the problem diagnosis process. 6. Then we click [Check to see if the problem is solved. 7. Check again and we have found the problem. Then we can solve the problem according to the prompts and try to plug and unplug the network cable again. The above is the solution to the problem that the win7 system cannot access the Internet. If you have this problem, you might as well

After updating to win11, some notebook batteries encountered the problem of exclamation marks when charging. This may be due to damage to our battery, or it may just be that the power management driver is out of date. Updating the driver can solve the problem. Solution to the exclamation mark when charging in win11: Method 1: 1. First try to pull out the laptop battery and connect it to the power supply for charging. 2. If the problem is solved, it means the battery is broken, just replace the battery. 3. If there is still an exclamation mark, it should be a driver problem. Try method two to solve it. Method two: 1. For driver problems, you need to first enter our notebook official website. (Take Lenovo as an example) 2. Then enter the "Service" option and enter "Driver Download" 3. After entering, select "Find Driver on this Site" and then search for our notebook model. 4. Enter

Users sometimes see an exclamation mark in messages when using an Apple phone, but they have never been able to remove it. In fact, the method of removing it is very simple. Today, let me share with you the detailed method of removing the exclamation mark. How to solve the exclamation mark in messages on Apple mobile phones: Reset iMessage, restart the phone, clear text messages, and replace the sim card. 1. If the exclamation mark cannot be removed, first check whether it is caused by iMessage settings. 2. Find the iMessage information management function in iPhone, that is, enter "Settings" and select the "Message" option. 3. Turn off the iMessage messaging service and then re-enable it. In addition, you need to select the device used to send and receive iMessage to complete the activation process. 4. If the above methods still do not work
