Search⌘ K
AI Features

Generating Excerpts of Text

Explore how to create precise text excerpts using Laravel's excerpt helper method. Understand how to customize excerpt length and omission strings to effectively highlight search phrases in your web applications.

We'll cover the following...

The excerpt helper method

It is used to generate an excerpt from a piece of text based on the first occurrence provided phrase. This method is handy for displaying the results of a user search. The basic structure of the excerpts is shown below:

PHP
<?php
/**
* Version: Laravel 9
*
* @return string|null
*/
public static function excerpt(
string $text,
string $phrase = '',
array $options = []
);

The excerpt method would return a string if it could ...