PHP Classes

File: examples/PcreRegexAndStringFunctions.php

Recommend this page to a friend!
  Classes of zinsou A.A.E.Moïse   PHP Dictionary to Array class   examples/PcreRegexAndStringFunctions.php   Download  
File: examples/PcreRegexAndStringFunctions.php
Role: Example script
Content type: text/plain
Description: example script
Class: PHP Dictionary to Array class
Manipulate value collections as arrays or objects
Author: By
Last change:
Date: 5 years ago
Size: 3,513 bytes
 

Contents

Class file image Download
with an xDict object no matter the data your xDict object contains you can use the PCRE REGEX functions<br>
and string functions like str_replace,str_ireplace and substr_replace without stress of invalid data types errors
for the following source:<br>
<?php highlight_string('<?php
require_once(\'../../xdict.class.php\');


$subject =explode(\'\' ,\'Aaaaaa Bbb\');
$subject[]=xdict(0);
$subj=xdict(0);
$subj->fill_with($subject);


echo \'<pre>\';
var_dump(
$subj->preg_replace_callback_array(
    [
        \'~[a]+~i\' => function ($match) {
            return strlen($match[0]). \' matches for "a" found\';
        },
        \'~[b]+~i\' => function ($match) {
           return strlen($match[0]). \' matches for "b" found\';
        }
    ]
   
));

echo \'<br><br><br>\';

var_dump($subj2->preg_grep(\'~[a]+~i\',0));

echo \'<br><br><br>\';

var_dump($subj2->preg_grep(\'~[a]+~i\',PREG_GREP_INVERT));

echo \'<br><br><br>\';

var_dump($subj2->preg_filter(\'~[a]+~i\',\'gotcha\'));

echo \'<br><br><br>\';

var_dump($subj2->preg_replace(\'~[a]+~i\',\'gotcha\'));

echo \'<br><br><br>\';

$subj->preg_replace_callback(\'~[a]+~i\' ,function ($match) {
            return strlen($match[0]). \' matches for "a" found\';
        }
)
);
echo \'<br><br><br>\';

var_dump($subj->str_ireplace(\'a\',\'k\'));

echo \'<br><br><br>\';

var_dump($subj->str_ireplace(\'a\',\'k\'));

echo \'<br><br><br>\';

var_dump($subj->substr_replace(\'u\',0,3));

echo \'<br><br><br>\';


$subj=xdict(0);
$subj->explode(\' \',\'this is the great XDict object explode method test\');
$subj->str_split(\'this is the great XDict object str_split method test\',4);
$subj->mb_split(\'\s\',\'this is the great XDict object mb_split method test\');
$subj->preg_split(\'/[\s,]+/\',\'this is the great XDict object preg_split method test\');
$subj->print_xr();
?>'
)
;
?><br>
 you got the following result:
<?php

require_once('./../xdict.class.php');


$subject =explode(' ' ,'Aaaaaa Bbb');
$subject[]=xdict(0);
$subj=xdict(0);
$subj->fill_with($subject);


echo
'<pre>';
var_dump(
$subj->preg_replace_callback_array(
    [
       
'~[a]+~i' => function ($match) {
            return
strlen($match[0]). ' matches for "a" found';
        },
       
'~[b]+~i' => function ($match) {
           return
strlen($match[0]). ' matches for "b" found';
        }
    ]
   
));

echo
'<br><br><br>';

var_dump($subj->preg_grep('~[a]+~i',0));

echo
'<br><br><br>';

var_dump($subj->preg_grep('~[a]+~i',PREG_GREP_INVERT));

echo
'<br><br><br>';

var_dump($subj->preg_filter('~[a]+~i','gotcha'));

echo
'<br><br><br>';

var_dump($subj->preg_replace('~[a]+~i','gotcha'));

echo
'<br><br><br>';

var_dump(
$subj->preg_replace_callback('~[a]+~i' ,function ($match) {
            return
strlen($match[0]). ' matches for "a" found';
        }
)
);

echo
'<br><br><br>';

var_dump($subj->str_ireplace('a','k'));

echo
'<br><br><br>';

var_dump($subj->str_ireplace('a','k'));

echo
'<br><br><br>';

var_dump($subj->substr_replace(['u','o','a'],0,3));

echo
'<br><br><br>';

$subj=xdict(0);
$subj->explode(' ','this is the great XDict object explode method test');
$subj->str_split('this is the great XDict object str_split method test',4);
$subj->mb_split('\s','this is the great XDict object mb_split method test');
$subj->preg_split('/[\s,]+/','this is the great XDict object preg_split method test');
$subj->print_xr();
?>