PHPackages                             s1syphos/php-gesetze - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. s1syphos/php-gesetze

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

s1syphos/php-gesetze
====================

Linking german legal norms, dependency-free &amp; GDPR-friendly

0.7.2(3y ago)4281GPL-3.0PHPPHP ^7.4|^8.0

Since Nov 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/S1SYPHOS/php-gesetze)[ Packagist](https://packagist.org/packages/s1syphos/php-gesetze)[ Docs](https://github.com/S1SYPHOS)[ RSS](/packages/s1syphos-php-gesetze/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (3)Versions (11)Used By (1)

php-gesetze
===========

[](#php-gesetze)

[![License](https://camo.githubusercontent.com/150a357b123b3369c1feabcecbae8895791291ea2a79ac9103b9f3f040b5b0cb/68747470733a2f2f62616467656e2e6e65742f62616467652f6c6963656e73652f47504c2f626c7565)](https://codeberg.org/S1SYPHOS/php-gesetze/src/branch/main/LICENSE) [![Packagist](https://camo.githubusercontent.com/cd03adb36300c4fe7f151c2d22bd2c77b42206a3d0fd1bfe8fc1334965aa8ce5/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f7331737970686f732f7068702d67657365747a65)](https://packagist.org/packages/s1syphos/php-gesetze) [![Build](https://camo.githubusercontent.com/ddbf651699ceb3fb931b553ce54ce9455a3e971d59463e2775a5300d5cf0f311/68747470733a2f2f63692e636f6465626572672e6f72672f6170692f6261646765732f5331535950484f532f7068702d67657365747a652f7374617475732e737667)](https://codeberg.org/S1SYPHOS/php-gesetze/issues)

Linking german legal norms, dependency-free &amp; GDPR-friendly. `php-gesetze` automatically transforms legal references into `a` tags - batteries included.

There's also a Python port of this library, called [`py-gesetze`](https://codeberg.org/S1SYPHOS/py-gesetze).

For API documentation (powered by [phpDocumentor](https://www.phpdoc.org)), see [here](https://s1syphos.codeberg.page/php-gesetze).

Installation
------------

[](#installation)

It's available for [Composer](https://getcomposer.org):

```
composer require s1syphos/php-gesetze

```

Getting started
---------------

[](#getting-started)

Upon invoking the main class, you may specify your preferred provider (or 'driver'), like this:

```
$object = new \S1SYPHOS\Gesetze\Gesetz('dejure');
```

It's also possible to specify selected of two or more drivers as array:

```
$object = new \S1SYPHOS\Gesetze\Gesetz(['dejure', 'buzer']);
```

**Note:** This defaults to all available drivers, which is a good overall choice, simply because of the vast array of supported laws. Possible values are `gesetze`, `'dejure'`, `'buzer'` and `'lexparency'`.

Out of the box, `php-gesetze` cycles through all known drivers until a match is found.

Usage
-----

[](#usage)

From there, the following functions are available:

### `analyze(string $string): array`

[](#analyzestring-string-array)

Analyzes a single legal norm:

```
$result = \S1SYPHOS\Gesetze\Gesetz::analyze('Art. 1 II GG');

var_dump($result);

# array(6) {
#   ["norm"]=>
#   string(1) "1"
#   ["absatz"]=>
#   string(2) "II"
#   ["satz"]=>
#   string(0) ""
#   ["nr"]=>
#   string(0) ""
#   ["lit"]=>
#   string(0) ""
#   ["gesetz"]=>
#   string(2) "GG"
# }
```

### `validate(string $string): bool`

[](#validatestring-string-bool)

Validates a single legal norm (across all selected providers:

```
$obj = new \S1SYPHOS\Gesetze\Gesetz();

var_dump($obj->validate('§ 433 II BGB'));

# bool(true)

foreach ($obj->extract('While § 433 II BGB exists, Art. 4c GG does not!') as $match) {
    var_dump($obj->validate($match);
}

# bool(true)
# bool(false)
```

**Note:** In the context of this library, being *valid* means *linkable by at least one provider*, as in *to be found in their database*.

### `roman2arabic(string $string): string`

[](#roman2arabicstring-string-string)

Converts roman numerals to arabic numerals:

```
echo \S1SYPHOS\Gesetze\Gesetz::roman2arabic('IX');

# 9
```

### `extract(string $string): array`

[](#extractstring-string-array)

Extracts legal norms as array of strings:

```
$obj = new \S1SYPHOS\Gesetze\Gesetz();

$result = $obj->extract('This string contains Art. 12 Abs. 1 GG and Art. 2 Abs. 2 DSGVO - for educational purposes only.')

var_dump($result);

# array(2) {
#   [0]=>
#   string(17) "Art. 12 Abs. 1 GG"
#   [1]=>
#   string(19) "Art. 2 Abs. 2 DSGVO"
# }
```

### `gesetzify(string $string, callable $callback): string`

[](#gesetzifystring-string-callable-callback-string)

Transforms legal references into HTML link tags:

```
$obj = new \S1SYPHOS\Gesetze\Gesetz();

echo $obj->gesetzify('This is a simple text, featuring § 1 I Nr. 1 BGB as well as Art. 4c GG');

# This is a simple text, featuring § 1 I Nr. 1 BGB as well as Art. 4c GG
```

**Note:** For more flexibility, you may use your own `callback` method as second parameter of `gesetzify`. Callbacks are being passed arrays representing matched legal norms. This way, you could highlight them using `` tags instead of converting them into `a` tags. Default: (private) method `linkify`

Example
-------

[](#example)

```
include_once 'vendor/autoload.php';

# Insert test string
$text  = '';
$text .= 'This is a simple HTML text.';
$text .= 'It contains legal norms, like Art. 12 I GG.';
$text .= '.. or § 433 II nr. 2 BGB!';
$text .= '';

# Initialize object
$obj = new \S1SYPHOS\Gesetze\Gesetz();

# Transform text
echo $obj->gesetzify($text);

# This is a simple HTML text.
# It contains legal norms, like Art. 12 I GG.
# .. or § 433 II nr. 2 BGB!
#
```

**Note:** Caching the result (to avoid repeated lookups &amp; save resources) is beyond the scope of this library and therefore totally up to you!

Configuration
-------------

[](#configuration)

There are several settings you may use in order to change the behavior of the library:

### `$object->drivers (array)`

[](#object-drivers-array)

Associative array, holding all available drivers (already initialized), where the corresponding keys are `'gesetze'`, `'dejure'`, `'buzer'` &amp; `'lexparency'` (default).

### `$object->pattern (string)`

[](#object-pattern-string)

The regex responsible for detecting legal norms. For reference, it amounts to this:

```
'/(?:§+|Art\.?|Artikel)\s*(\d+(?:\w\b)?)\s*(?:(?:Abs(?:atz|\.)\s*)?((?:\d+|[XIV]+)(?:\w\b)?))?\s*(?:(?:S\.|Satz)\s*(\d+))?\s*(?:(?:Nr\.|Nummer)\s*(\d+(?:\w\b)?))?\s*(?:(?:lit\.|litera|Buchst\.|Buchstabe)\s*([a-z]?))?.{0,10}?(\b[A-Z][A-Za-z]*[A-Z](?:(?:\s|\b)[XIV]+)?)/'
```

**Note**: Well, more or less - for the latest revision, please refer to `src/Traits/Regex.php`!

### `$object->attributes (array)`

[](#object-attributes-array)

Other HTML attributes to be applied globally:

```
$object->attributes = [
    'attr1' => 'some-value',
    'attr2' => 'other-value',
];

# .. would generate links like this:

§ 1 SomeLaw
```

### `$object->title (false|string)`

[](#object-title-falsestring)

Controls `title` attribute:

OptionDescription`false`No `title` attribute (default)`'light'`abbreviated law (eg 'GG')`'normal'`complete law (eg 'Grundgesetz')`'full'`official heading (eg 'Artikel 12')Credits
-------

[](#credits)

The regular expression used in this library is based on the [`jura_regex`](https://github.com/kiersch/jura_regex) regex package by Philipp Kiersch (originally written in Python).

Special Thanks
--------------

[](#special-thanks)

I'd like to thank everybody that's making free &amp; open source software - you people are awesome. Also I'm always thankful for feedback and bug reports :)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~86 days

Total

10

Last Release

1259d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5933072731cd628e1ef2bdc59bc81da16dac859145a3be2dc5c83aab9095179b?d=identicon)[S1SYPHOS](/maintainers/S1SYPHOS)

---

Top Contributors

[![S1SYPHOS](https://avatars.githubusercontent.com/u/12161504?v=4)](https://github.com/S1SYPHOS "S1SYPHOS (70 commits)")

---

Tags

bjmbuzerdejuregesetzegesetze-im-internetlawlawslegallexparencylawlegaldejuredejure.orgbjmlawslegal techgesetzegesetze-im-internet.debuzerbuzer.delexparencylexparency.de

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/s1syphos-php-gesetze/health.svg)

```
[![Health](https://phpackages.com/badges/s1syphos-php-gesetze/health.svg)](https://phpackages.com/packages/s1syphos-php-gesetze)
```

###  Alternatives

[spatie/laravel-cookie-consent

Make your Laravel app comply with the crazy EU cookie law

1.5k4.7M20](/packages/spatie-laravel-cookie-consent)[comcast/php-legal-licenses

A utility to generate a Licenses file containing the full license text for every dependency in your project for legal purposes.

821.1M9](/packages/comcast-php-legal-licenses)[amstaffix/pagination

Simple pagination

46290.4k6](/packages/amstaffix-pagination)[faonni/module-smart-category

SmartCategory module is a base of Smart Categories functionality.

8289.3k3](/packages/faonni-module-smart-category)[maize-tech/laravel-legal-consent

Laravel Legal Consent

521.8k](/packages/maize-tech-laravel-legal-consent)[sitegeist/silhouettes

Preconfigure property-silhuettes that can be applied to various properties of multiple NodeTypes.

16157.5k](/packages/sitegeist-silhouettes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
