NOTE: This repository is part of Google Cloud PHP. Any
support requests, bug reports, or development contributions should be directed to
that project.
Provides natural language understanding technologies to developers, including sentiment analysis, entity analysis,
entity sentiment analysis, content classification, and syntax analysis. This API is part of the larger Cloud Machine Learning API family.
Installation
To begin, install the preferred dependency manager for PHP, Composer.
Now install this component:
$ composer require google/cloud-language
Authentication
Please see our Authentication guide for more information
on authenticating your client. Once authenticated, you'll be ready to start making requests.
Sample
require 'vendor/autoload.php';
use Google\Cloud\Language\LanguageClient;
$language = new LanguageClient();
// Analyze a sentence.
$annotation = $language->annotateText('Greetings from Michigan!');
// Check the sentiment.
if ($annotation->sentiment() > 0) {
echo "This is a positive message.\n";
}
// Detect entities.
$entities = $annotation->entitiesByType('LOCATION');
foreach ($entities as $entity) {
echo $entity['name'] . "\n";
}
// Parse the syntax.
$tokens = $annotation->tokensByTag('NOUN');
foreach ($tokens as $token) {
echo $token['text']['content'] . "\n";
}
Debugging
Please see our Debugging guide
for more information about the debugging tools.
Version
This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in
any minor or patch releases. We will address issues and requests with the highest priority.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [1.0.1 (latest)](/php/docs/reference/cloud-language/latest)\n- [1.0.0](/php/docs/reference/cloud-language/1.0.0)\n- [0.34.3](/php/docs/reference/cloud-language/0.34.3)\n- [0.33.0](/php/docs/reference/cloud-language/0.33.0)\n- [0.32.7](/php/docs/reference/cloud-language/0.32.7)\n- [0.31.3](/php/docs/reference/cloud-language/0.31.3)\n- [0.30.2](/php/docs/reference/cloud-language/0.30.2)\n- [0.29.0](/php/docs/reference/cloud-language/0.29.0)\n- [0.28.5](/php/docs/reference/cloud-language/0.28.5) \n\nGoogle Cloud PHP Natural Language\n=================================\n\n\u003e Idiomatic PHP client for [Cloud Natural Language](https://cloud.google.com/natural-language/).\n\n[](https://packagist.org/packages/google/cloud-language) [](https://packagist.org/packages/google/cloud-language)\n\n**NOTE:** This repository is part of [Google Cloud PHP](https://github.com/googleapis/google-cloud-php). Any\nsupport requests, bug reports, or development contributions should be directed to\nthat project.\n\nProvides natural language understanding technologies to developers, including sentiment analysis, entity analysis,\nentity sentiment analysis, content classification, and syntax analysis. This API is part of the larger Cloud Machine Learning API family.\n\n### Installation\n\nTo begin, install the preferred dependency manager for PHP, [Composer](https://getcomposer.org/).\n\nNow install this component: \n\n $ composer require google/cloud-language\n\n### Authentication\n\nPlease see our [Authentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) for more information\non authenticating your client. Once authenticated, you'll be ready to start making requests.\n\n### Sample\n\n require 'vendor/autoload.php';\n\n use Google\\Cloud\\Language\\LanguageClient;\n\n $language = new LanguageClient();\n\n // Analyze a sentence.\n $annotation = $language-\u003eannotateText('Greetings from Michigan!');\n\n // Check the sentiment.\n if ($annotation-\u003esentiment() \u003e 0) {\n echo \"This is a positive message.\\n\";\n }\n\n // Detect entities.\n $entities = $annotation-\u003eentitiesByType('LOCATION');\n\n foreach ($entities as $entity) {\n echo $entity['name'] . \"\\n\";\n }\n\n // Parse the syntax.\n $tokens = $annotation-\u003etokensByTag('NOUN');\n\n foreach ($tokens as $token) {\n echo $token['text']['content'] . \"\\n\";\n }\n\n### Debugging\n\nPlease see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md)\nfor more information about the debugging tools.\n\n### Version\n\nThis component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in\nany minor or patch releases. We will address issues and requests with the highest priority.\n\n### Next Steps\n\n1. Understand the [official documentation](https://cloud.google.com/natural-language/docs/).\n2. Take a look at [in-depth usage samples](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/language)."]]