Current Location: Home> Latest Articles> Complete Guide to Implementing Text and Image Content Review with PHP and Baidu AI

Complete Guide to Implementing Text and Image Content Review with PHP and Baidu AI

gitbox 2025-07-30

Introduction

With the widespread use of social media and content sharing platforms, user-uploaded text and images may contain inappropriate or violating content. To ensure a better user experience on the platform, we need to review this content. This article will introduce how to implement text and image review functionalities using PHP and Baidu AI.

Text Review

Purpose of Text Review

The purpose of text review is to identify and filter out inappropriate text content, such as sensitive words, pornography, violence, and politically sensitive content.

Preparation

Before we begin, you need to register on Baidu AI platform and create a text review application. Then, you need to include Baidu AI SDK in your PHP code:

require_once 'AipContentCensor.php';<br>const APP_ID = 'your_app_id';<br>const API_KEY = 'your_api_key';<br>const SECRET_KEY = 'your_secret_key';<br>$client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);

Initiating a Text Review Request

After instantiating the client, you can use Baidu AI's API to initiate a text review request. Below is a simple example:

$text = "This is a text containing sensitive words";<br>$result = $client->textCensorUserDefined($text);<br>if ($result['conclusionType'] == 1) {<br>  echo "Review passed";<br>} else {<br>  echo "Review failed";<br>}

In this example, we use the textCensorUserDefined API to review a text containing sensitive words. The API will return a result where the conclusionType field indicates the review result, with 1 meaning passed and 2 meaning failed.

Image Review

Purpose of Image Review

The purpose of image review is to identify and filter out inappropriate images, such as pornography, blood, violence, and politically sensitive content.

Preparation

Similarly, before starting, you need to register on Baidu AI platform and create an image review application. Then, you need to instantiate a Baidu AI Client using the SDK:

$client = new AipImageCensor(APP_ID, API_KEY, SECRET_KEY);

Initiating an Image Review Request

After instantiating the client, you can use Baidu AI's API to initiate an image review request. Below is a simple example:

$image = file_get_contents("image.jpg");<br>$result = $client->imageCensorUserDefined($image);<br>if ($result['conclusionType'] == 1) {<br>  echo "Review passed";<br>} else {<br>  echo "Review failed";<br>}

In this example, we use the imageCensorUserDefined API to review an image. The API will return a result where the conclusionType field indicates the review result, with 1 meaning passed and 2 meaning failed.

Conclusion

By using PHP and Baidu AI, we can easily implement text and image review functionalities. This feature is essential for protecting user privacy and improving platform content quality. We hope this article has been helpful to you. Thank you for reading!