PHP code example of sofac / rfc-3986

1. Go to this page and download the library: Download sofac/rfc-3986 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/ */

    

sofac / rfc-3986 example snippets


use Sofac\Standards\Rfc3986\Character;
use Sofac\Standards\Rfc3986\Enums\DelimiterRegex;

/* SOME USEFUL CONSTANTS */


$genDelims = Character::GEN_DELIMS;

$subDelims = Character::SUB_DELIMS;

echo "<pre>";

print_r($genDelims);

echo "</pre>";
/*
result $subDelims
   Array
(
    [0] => :
    [1] => /
    [2] => ?
    [3] => #
    [4] => [
    [5] => ]
    [6] => @
)
*/


/* METHODS */

/* Returns already escaped sub-delims for use in regex. */
$sub = Character::subDelimsForRegex(); // '\!\$&'\(\)\*\+,;\='

/* Returns already escaped sub-delims for use in regex. except */
$subExcept = Character::subDelimsForRegex(')','=');// '\!\$&'\(\*\+,;'

/* Regex builder, still under development. */
$regex = Character::makerRegex(
    DelimiterRegex::SLASH_DELIMITER, '(?:[^', Character::unreservedForRegex(), Character::subDelimsForRegex(), Character::gemDelimsForRegex("#", "[", "]"), '%]++|', Character::percentIdentifyRegex(), ')'
);

echo $regex; /* result: '/(?:[^A-Za-za-z0-9\-\._~\!\$&'\(\)\*\+,;\=\:\/\?@%]++|%(?![A-Fa-f0-9]{2}))/' */