Compilation failed: invalid range in character class at offset 4
Escape the hyphen:
if (!preg_match("/^[\w\-:]+$/", $tag)) {
or put it at the beginning of character class:
if (!preg_match("/^[-\w:]+$/", $tag)) {
or at the end:
if (!preg_match("/^[\w:-]+$/", $tag)) {
PHP 5.6.10 - preg_match(): Compilation failed: invalid range in character class at offset 100
In class -
is a range operator you need to escape it with \
[a-zA-Z0-9_\-\s]
preg_match(): Compilation failed: invalid range in character class at offset 20
For php version is 7.3 and above use \-
instead of -
, so your final code :
Route::get('{path}',"HomeController@index")->where( 'path', '([A\-z\d\-\/_.]+)?' );
Route::get('{path}',"HomeController@index")->where('path','[\-a\-z0\-9_\s]+');
preg_replace(): Compilation failed: invalid range in character class at offset 11 in Laravel Slug
You have a extra -
after \s
.
Replace:
$string = preg_replace("/[^a-z0-9_\s-ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/", "", $string);
with
$string = preg_replace("/[^a-z0-9_\sءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/", "", $string);
Or fix it to match your regex, like escaping it \-
.
preg_match(): Compilation failed: invalid range in character class at offset 15
The hyphen (-
) needs to be escaped because of its position inside of the character class.
Note: Inside of a character class the hyphen has special meaning. You can place it as the first or last character of the class. In some regex implementations, you can also place directly after a range. If you place the hyphen anywhere else you need to precede it with a backslash in order to add it to your character class.
if(preg_match("/^[a-zA-Z\s,.'\-\pL]+$/u", $name)) { ...
^^
You could write the regular expressions as follows:
if(preg_match("/^[\pL\s,.'-]+$/u", $name)) { ...
Related Topics
Startswith() and Endswith() Functions in PHP
Fatal Error: Maximum Execution Time of 30 Seconds Exceeded
How to Create a Pdo Parameterized Query With a Like Statement
Difference Between Bindparam and Bindvalue
How to Check If a Url Exists Via PHP
How to Zip a Whole Folder Using PHP
How to Get a Form Input Array into a PHP Array
Pdoexception Sqlstate[Hy000] [2002] No Such File or Directory
How to Decode Unicode Escape Sequences Like "\U00Ed" to Proper Utf-8 Encoded Characters
How to Convert Json String to Array
PHP Display Image Blob from MySQL
PHP - Should I Call Exit() After Calling Location: Header
Open_Basedir Restriction in Effect. File(/) Is Not Within the Allowed Path(S):
How to Get the Cookies from a PHP Curl into a Variable