preg_replace():编译失败:Laravel Slug 中偏移量 11 处字符 class 的无效范围
preg_replace(): Compilation failed: invalid range in character class at offset 11 in Laravel Slug
我正在从我的博客应用程序构建一个 Arabic Slug 系统
当我添加新的 Slug 时出现此错误
preg_replace(): Compilation failed: invalid range in character class at offset 11
控制器
public function slug($string, $separator = '-') {
if (is_null($string)) {
return "";
}
$string = trim($string);
$string = mb_strtolower($string, "UTF-8");;
$string = preg_replace("/[^a-z0-9_\s-ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/", "", $string);
$string = preg_replace("/[\s-]+/", " ", $string);
$string = preg_replace("/[\s_]/", $separator, $string);
return $string;
}
public function store(Request $request)
{
$this->validate($request, array(
'title' => 'required|max:255',
'slug' => 'required|min:3|max:255|unique:posts',
'body' => 'required',
));
$post = new Post;
$post->title = $request->input('title');
$post->slug = $this->slug($request->slug);
$post->body = $request->input('body');
$post->save();
return redirect('admin/posts')->with('success', 'post is successfully saved');
}
路线
Route::get('post/{slug}', 'PagesController@post')->name('post.show');
你在\s
之后还有一个额外的-
。
替换:
$string = preg_replace("/[^a-z0-9_\s-ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/", "", $string);
和
$string = preg_replace("/[^a-z0-9_\sءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/", "", $string);
或修复它以匹配您的正则表达式,例如转义它 \-
。
我正在从我的博客应用程序构建一个 Arabic Slug 系统
当我添加新的 Slug 时出现此错误
preg_replace(): Compilation failed: invalid range in character class at offset 11
控制器
public function slug($string, $separator = '-') {
if (is_null($string)) {
return "";
}
$string = trim($string);
$string = mb_strtolower($string, "UTF-8");;
$string = preg_replace("/[^a-z0-9_\s-ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/", "", $string);
$string = preg_replace("/[\s-]+/", " ", $string);
$string = preg_replace("/[\s_]/", $separator, $string);
return $string;
}
public function store(Request $request)
{
$this->validate($request, array(
'title' => 'required|max:255',
'slug' => 'required|min:3|max:255|unique:posts',
'body' => 'required',
));
$post = new Post;
$post->title = $request->input('title');
$post->slug = $this->slug($request->slug);
$post->body = $request->input('body');
$post->save();
return redirect('admin/posts')->with('success', 'post is successfully saved');
}
路线
Route::get('post/{slug}', 'PagesController@post')->name('post.show');
你在\s
之后还有一个额外的-
。
替换:
$string = preg_replace("/[^a-z0-9_\s-ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/", "", $string);
和
$string = preg_replace("/[^a-z0-9_\sءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]#u/", "", $string);
或修复它以匹配您的正则表达式,例如转义它 \-
。