Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Shared :: "regex/scriptMatches.php"
- class scriptMatchClass {
- public $regex = [];
- public function __construct(){
- $file = file_get_contents("{$_SERVER['DOCUMENT_ROOT']}/Shared/scripts/regex/scriptMatches.csv");
- $lines = explode("\r\n", $file);
- $parts = [];
- foreach ($lines as $line) {
- $key = substr($line, 0, strpos($line, "="));
- $value = substr($line, strpos($line, "=") + strlen("="));
- $parts[$key] = $value;
- }
- // Escape 'before' and 'after' parts using '/' as the delimiter
- foreach (['before', 'after'] as $key) {
- $parts[$key] = preg_quote($parts[$key], '/'); // Use '/' as the delimiter here
- }
- $this->regex = [];
- foreach ($parts as $key => $value) {
- if (!in_array($key, ['before', 'after'])) {
- // Escape the pattern using '/' as the delimiter
- $escapedPattern = preg_quote($parts[$key], '/');
- $this->regex[$key] = '/' . $parts['before'] . $escapedPattern . $parts['after'] . '/mi';
- }
- }
- }
- public function asName($line) {
- // Apply the regex for both 'full' and 'short' patterns
- $fullMatches = preg_match_all($this->regex['full'], $line, $matchesFull, PREG_SET_ORDER);
- $shortMatches = preg_match_all($this->regex['short'], $line, $matchesShort, PREG_SET_ORDER);
- if ($fullMatches > 0) {
- $matches = $matchesFull[0];
- } elseif ($shortMatches > 0) {
- $matches = $matchesShort[0];
- } else {
- return [null, null];
- }
- $fullFile = isset($matches['full']) ? $matches['full'] : '';
- $shortFile = isset($matches['short']) ? $matches['short'] : '';
- return [$fullFile, $shortFile];
- }
- public function jRmNumeric(&$m = false) {
- if (!is_array($m)) {
- return;
- }
- foreach ($m as $key => $value) {
- if ($key == 0) {
- continue;
- }
- if ($key == strval(intval($key))) {
- unset($m[$key]);
- } else {
- if (is_numeric($value)) {
- $m[$key] = intval($m[$key]);
- }
- }
- }
- return $m;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement