PMA\libraries\controllers\table\TableSearchController::_getRegexReplaceRows PHP Метод

_getRegexReplaceRows() приватный Метод

Finds and returns Regex pattern and their replacements
private _getRegexReplaceRows ( integer $columnIndex, string $find, string $replaceWith, string $charSet ) : array
$columnIndex integer index of the column
$find string string to find in the column
$replaceWith string string to replace with
$charSet string character set of the connection
Результат array Array containing original values, replaced values and count
    private function _getRegexReplaceRows($columnIndex, $find, $replaceWith, $charSet)
    {
        $column = $this->_columnNames[$columnIndex];
        $sql_query = "SELECT " . Util::backquote($column) . "," . " 1," . " COUNT(*)" . " FROM " . Util::backquote($this->db) . "." . Util::backquote($this->table) . " WHERE " . Util::backquote($column) . " RLIKE '" . $GLOBALS['dbi']->escapeString($find) . "' COLLATE " . $charSet . "_bin";
        // here we
        // change the collation of the 2nd operand to a case sensitive
        // binary collation to make sure that the comparison is case sensitive
        $sql_query .= " GROUP BY " . Util::backquote($column) . " ORDER BY " . Util::backquote($column) . " ASC";
        $result = $this->dbi->fetchResult($sql_query, 0);
        if (is_array($result)) {
            /* Iterate over possible delimiters to get one */
            $delimiters = array('/', '@', '#', '~', '!', '$', '%', '^', '&', '_');
            $found = false;
            for ($i = 0, $l = count($delimiters); $i < $l; $i++) {
                if (strpos($find, $delimiters[$i]) === false) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                return false;
            }
            $find = $delimiters[$i] . $find . $delimiters[$i];
            foreach ($result as $index => $row) {
                $result[$index][1] = preg_replace($find, $replaceWith, $row[0]);
            }
        }
        return $result;
    }