1. Go to this page and download the library: Download dixflatlinr/preg_return 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/ */
dixflatlinr / preg_return example snippets
preg_return(string $pattern, string $subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
preg_return_all(string $pattern, string $subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
preg_return_replace(string $pattern, string $replacement, string &$subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
RX::pregReturn(string $pattern, string $subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
RX::pregReturnAll(string $pattern, string $subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
RX::pregReturnReplace(string $pattern, string $replacement, string &$subject, $indexesToReturn = null, int $flags = 0, int $offset = 0)
preg_match(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int|false
<?
use DF\App\Helper\RX;
null, gives back the preg_match return value
preg_return('~(a)(?<namedindex>b)~is','ab'); //=> 1;
RX::pregReturn('~(a)(?<namedindex>b)~is','ab'); //=> 1;
//Using an empty array or string returns the whole results array
preg_return('~(a)(?<namedindex>b)~is','ab', []);
/* =>
array(4) {
[0]=>
string(2) "ab"
[1]=>
string(1) "a"
["namedindex"]=>
string(1) "b"
[2]=>
string(1) "b"
}
*/
//=== 0, gives back the text that matched the full pattern
preg_return('~(a)(?<namedindex>b)~is','ab', 0); //=> 'ab'
//=== 1, gives back text that matched the first captured parenthesized subpattern
preg_return('~(a)(?<namedindex>b)~is','ab', 1); //=> 'a'
//=== 'namedindex', gives back text that matched the given named group
preg_return('~(a)(?<namedindex>b)~is','ab', 'namedindex'); //=> 'b'
//Using an array with indexes or named groups returns those keyed accordingly
preg_return('~(a)(?<namedindex>b)~is','ab', [1,'namedindex']);//=> [1 => 'a', 'namedindex' => b]
//Using preg_return_replace modifies the provided subject variable and returns the matched element before replacement
$subject = 'first_second_third';
$r = preg_return_replace('~^(first)_(second)_(?<third>third)$~is', '\1_\2_XXX', $subject, 3);
/*
$r = "third";
$subject = "first_second_XXX";
*/
bash
composer
&$matches
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.