PHP code example of s1syphos / php-gesetze

1. Go to this page and download the library: Download s1syphos/php-gesetze library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

s1syphos / php-gesetze example snippets


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

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

$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"
# }

$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)

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

# 9

$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"
# }

$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 <a href="https://www.gesetze-im-internet.de/bgb/__1.html" title="§ 1 Beginn der Rechtsfähigkeit">§ 1 I Nr. 1 BGB</a> as well as Art. 4c GG



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

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

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

# <div>This is a <b>simple</b> HTML text.
# It contains legal norms, like <a href="https://www.gesetze-im-internet.de/gg/art_12.html" target="_blank">Art. 12 I GG</a>.
# .. or <a href="https://www.gesetze-im-internet.de/bgb/__433.html" target="_blank">§ 433 II nr. 2 BGB</a>!
# </div>

'/(?:§+|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]+)?)/'

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

# .. would generate links like this:

<a href="https://example.com/some-law" attr1="some-value" attr2="other-value">§ 1 SomeLaw</a>
text
composer