在给大家讲述这个问题之前,先给大家看一段nginx配置. 我们用到了 set-misc-nginx-module
location /test/ {
default_type text/html;
set_md5 $hash "secret"$remote_addr;
echo $hash;
}这样输出来的内容,可能是下面这样的
202cb962ac59075b964b07152d234b70
更多xxxxxx相关文章请关注php中文网!
想到的肯定是使用模块来实现, 但只能这样吗? 有没有更方便的方式呢?有的.
我们可以巧妙地使用if + 正则表达式来实现这个小需求:
location /test/ {
default_type text/html;
set_md5 $hash "secret"$remote_addr;
if ( $hash ~ ^[\w][\w][\w][\w][\w][\w][\w][\w]([\w][\w][\w][\w][\w][\w][\w][\w]) ) {
set $hash $1;
}
echo $hash;
}访问/test/输出的就是:
ac59075b
更多Nginx if语句加正则表达式实现字符串截断相关文章请关注PHP中文网!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号