[英]How to split string by character and check format by regular expression
我知道Laravel支持使用正则表达式进行路由,如下所示
Route::get('user/{id}', function($id) {
//
})
->where('id', '[0-9]+');
如果我的端点像/ {size} / photo ,例如/100x100/foo.jpg ,我如何使用正则表达式检查大小是否有效?
我是正则表达式的新手。 谢谢
Route::get('{size}/{filename}.jpg', function($size, $filename) {
list($width, $height) = explode('x', $size);
// Now use $width and $height, and enjoy life!
})
->where('size', '\d+x\d+');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.