如何逐字符分割并通过正则表达式检查格式

时间:2015-07-28 02:53:54

标签: php regex laravel

我知道Laravel支持使用正则表达式进行路由,如下所示

Route::get('user/{id}', function($id) {
    //
})
->where('id', '[0-9]+');

如果我的端点喜欢 / {size} / photo ,例如 /100x100/foo.jpg 如何使用正则表达式检查大小是否有效?

我是regex的新手。感谢

1 个答案:

答案 0 :(得分:0)

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+');