php - Laravel preg_match uri 验证器
问题描述
我正在使用 Laravel 和 Vue 安装一些应用程序,并且我使用的是 php 7.3,但 laravel 使用 5.6 运行。现在给我一个错误,例如:
preg_match():编译失败:偏移量 20 处的字符类范围无效
在文件夹 vendor\laravel\framework\src\Illuminate\Routing\Matching\UriValidator.php
这是代码
<?php
namespace Illuminate\Routing\Matching;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
class UriValidator implements ValidatorInterface
{
/**
* Validate a given rule against a route and request.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
* @return bool
*/
public function matches(Route $route, Request $request)
{
$path = $request->path() == '/' ? '/' : '/'.$request->path();
return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
}
}
解决方案
在你的 web.php 中试试这个
Route::get('{path}',function(){
return view('your.index');
})->where('path', '[A-z\d\-\/_.]+');
推荐阅读
- perl - 不能在没有包或对象引用的情况下调用方法“import”
- hadoop - 如何管理由于将流数据插入 Hive 而创建的小文件?
- powershell - 使用 Powershell 运行 .cmd 文件
- c - 切换 vs if ... else if ... else
- arduino - esp8266中创建的mdns服务无法浏览
- android - 如何在活动中设置片段并在recyclerview中添加cardview
- selenium - 如何在 TestNG.xml 中优先执行包?
- javascript - Laravel:javascript由于某些原因无法正常工作
- java - 无法重现 org.apache.hadoop.mapred.Child:运行子错误:java.lang.OutOfMemoryError:Java 堆空间错误
- gnu - GNU LD:重叠部分 (NOLOAD) 不会产生错误