loupe/context-cropper

A simple library to crop highlighted context

Fund package maintenance!
Toflar

dev-main 2025-03-21 14:09 UTC

This package is auto-updated.

Last update: 2025-03-21 14:11:56 UTC


README

A simple PHP library to crop highlighted context coming from e.g. a search engine.

Usage:

$context = 'Lorem ipsum dolor sit amet, <mark>consectetur</mark> adipiscing elit. Etiam eleifend, augue in dictum lacinia, nisi lacus mollis <mark>massa</mark>, a pulvinar felis dui nec nisl. Pellentesque justo erat, sollicitudin ac dolor finibus, dapibus lacinia diam.';

$cropper = new \Loupe\ContextCropper\ContextCropper(
    20, // Context length in characters
    '[…]',
    '<mark>',
    '</mark>'
);

echo $cropper->apply($context); // […]ipsum dolor sit amet, <mark>consectetur</mark> adipiscing elit. Etiam[…]lacinia, nisi lacus mollis <mark>massa</mark>, a pulvinar felis dui[…]