Final Class Yiisoft\Db\Helper\DbStringHelper
| Inheritance | Yiisoft\Db\Helper\DbStringHelper |
|---|
String manipulation methods.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| isReadQuery() | Returns a value indicating whether an SQL statement is for read purpose. | Yiisoft\Db\Helper\DbStringHelper |
| normalizeFloat() | Returns string representation of a number value without a thousand separators and with dot as decimal separator. | Yiisoft\Db\Helper\DbStringHelper |
Method Details
Returns a value indicating whether an SQL statement is for read purpose.
| public static boolean isReadQuery ( string $sql ) | ||
| $sql | string |
The SQL statement. |
| return | boolean |
Whether an SQL statement is for read purpose. |
|---|---|---|
public static function isReadQuery(string $sql): bool
{
$pattern = '/^\s*(SELECT|SHOW|DESCRIBE)\b/i';
return preg_match($pattern, $sql) === 1;
}
Returns string representation of a number value without a thousand separators and with dot as decimal separator.
| public static string normalizeFloat ( float|string $value ) | ||
| $value | float|string |
The number value to be normalized. |
public static function normalizeFloat(float|string $value): string
{
if (is_float($value)) {
$value = (string) $value;
}
$value = str_replace([' ', ','], ['', '.'], $value);
/** @var string */
return preg_replace('/\.(?=.*\.)/', '', $value);
}
Signup or Login in order to comment.