{"id":28383172,"url":"https://github.com/swisnl/textsnippet","last_synced_at":"2025-06-25T07:31:02.443Z","repository":{"id":57063147,"uuid":"98652599","full_name":"swisnl/textsnippet","owner":"swisnl","description":"Create a snippet of text highlighting a given string","archived":false,"fork":false,"pushed_at":"2021-10-07T12:43:16.000Z","size":19,"stargazers_count":14,"open_issues_count":2,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-06T05:30:35.758Z","etag":null,"topics":["hacktoberfest","highlighter","php","search","summarization","text-processing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swisnl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-28T13:33:31.000Z","updated_at":"2023-10-31T01:40:20.000Z","dependencies_parsed_at":"2022-08-24T10:10:17.327Z","dependency_job_id":null,"html_url":"https://github.com/swisnl/textsnippet","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/swisnl/textsnippet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swisnl%2Ftextsnippet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swisnl%2Ftextsnippet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swisnl%2Ftextsnippet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swisnl%2Ftextsnippet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swisnl","download_url":"https://codeload.github.com/swisnl/textsnippet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swisnl%2Ftextsnippet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261826893,"owners_count":23215662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","highlighter","php","search","summarization","text-processing"],"created_at":"2025-05-30T05:12:06.392Z","updated_at":"2025-06-25T07:31:02.438Z","avatar_url":"https://github.com/swisnl.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SWIS Text Snippet\n\nEasy and fast way to create a snippet of text, for example for a search result. It will try and highlight the given words and give you the relevant text around it.\n\n[![Build Status](https://img.shields.io/travis/swisnl/textsnippet/master.svg)](https://travis-ci.org/swisnl/textsnippet)\n[![Latest Stable Version](https://img.shields.io/packagist/v/swisnl/textsnippet.svg)](https://packagist.org/packages/swisnl/textsnippet)\n[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://packagist.org/packages/swisnl/textsnippet)\n[![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen.svg)](https://plant.treeware.earth/swisnl/textsnippet)\n\n\n## Installation\n\nJust use composer to install the package. Or download and include the `TextSnipet.php` file.\n\n``composer require swisnl/textsnippet``\n\n\n## Examples\n\nSome examples based on a 3 paragraph long Lorum ipsum text.\n\n### Basic usage\n\n```php\n$snippet = new TextSnippet()\n$snippet-\u003ecreateSnippet('Lorem', $lorumIpsum);\n```\n\nWill result in:\n\n\n**Lorem** ipsum dolor sit amet, consectetur adipiscing elit. ... Etiam bibendum **lorem** nec tempus sollicitudin. ... Sed in dapibus **lorem**. ... Nunc turpis ipsum, bibendum quis sodales sed, ullamcorper et **lorem**. Donec et metus hendrerit, interdum elit ut, dignissim dui.\n\n\n### Setting highlight html\n\nYou can set the tags surrounding the highlighted text. The `%word%` tag is required.\n\n```php\n$snippet = new TextSnippet()\n$snippet-\u003esetHighlightTemplate('\u003cstrong\u003e%word%\u003c/strong\u003e')\n```\n\n### Setting min and max words\n\nSetting min and maxwords tells the class to try and keep the number of words between the min and max.\n\n```php\n// Defaults\n$minWords = 30;\n$maxWords = 100;\n```\n\nSetting min and max words.\n\n```php\n$snippet = new TextSnippet()\n$snippet-\u003esetMinWords(10);\n$snippet-\u003esetMaxWords(30);\n```\n\nThere is a known issue if you set min and max very close to eachother. It might not find the correct set of words/sentences to get exactly between the small gap.\n\n## Licence\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\nThis package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/swisnl/textsnippet) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.\n\n## SWIS :heart: Open Source\n\n[SWIS](https://www.swis.nl) is a web agency from Leiden, the Netherlands. We love working with open source software.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswisnl%2Ftextsnippet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswisnl%2Ftextsnippet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswisnl%2Ftextsnippet/lists"}