当前位置:首页 > 文章列表 > 文章 > php教程 > Laravel缓存键绑定URL防止内容错乱

Laravel缓存键绑定URL防止内容错乱

2026-03-29 09:30:46 0浏览 收藏
本文深入剖析了 Laravel 中使用 cache()->remember() 时因缓存键未与请求 URL 绑定而导致的严重数据污染问题——如所有页面返回相同标题,并给出了切实可行的解决方案:必须通过 md5 或 sha256 对 URL 进行哈希生成唯一、安全、兼容各缓存后端的键名,同时摒弃脆弱的正则解析,改用 DOMDocument 精确提取标题,并推荐采用 Guzzle 替代 file_get_contents 以增强健壮性与可控性;文章还延伸介绍了生产级优化策略,包括封装复用、失败降级、异步预热及反爬合规实践,助你真正实现高性能与高准确性的平衡。

Laravel 缓存键需动态绑定 URL 以避免内容混淆

本文详解 Laravel 中使用 cache()->remember() 时缓存键(cache key)必须唯一标识请求资源,否则会导致不同 URL 共享同一缓存值、返回错误标题等问题,并提供安全、可维护的实现方案。

本文详解 Laravel 中使用 cache()->remember() 时缓存键(cache key)必须唯一标识请求资源,否则会导致不同 URL 共享同一缓存值、返回错误标题等问题,并提供安全、可维护的实现方案。

在 Laravel 中为远程页面标题提取功能添加缓存,是提升批量爬取性能的有效手段。但初学者常犯的关键错误是:使用固定缓存键(如 'key')缓存依赖动态参数(如 $url)的结果。这会导致所有 URL 均写入并读取同一缓存项,最终全部返回首个被缓存的页面标题——正如问题中“所有标题相同”的现象。

根本原因在于:cache()->remember('key', ...) 中的 'key' 是硬编码字符串,与 $url 完全解耦。无论传入 https://example.com 还是 https://laravel.com,系统始终查找/写入名为 'key' 的缓存条目,自然造成数据污染。

✅ 正确做法是:将 URL 安全地融入缓存键,确保每个 URL 拥有唯一、可预测且无冲突的键名。推荐使用 md5() 或 sha256() 对 URL 哈希,既规避特殊字符(如 /, ?, #)引发的缓存驱动异常,又保证长度可控、分布均匀:

function getTitle(string $url): ?string
{
    // 使用哈希生成安全、唯一的缓存键
    $cacheKey = 'page_title_' . md5($url);

    $pages = cache()->remember(
        $cacheKey,
        now()->addDay(), // 缓存有效期:24 小时
        fn() => file_get_contents($url)
    );

    // 使用更健壮的 DOM 解析替代正则(见下方说明)
    if (preg_match('/]*>(.*?)<\/title>/ims', $pages, $matches)) {
        return trim($matches[1]);
    }

    return null;
}

⚠️ 重要注意事项

  • 不要直接拼接原始 URL 作为键(如 'key-'.$url):URL 中可能含空格、问号、井号等,某些缓存后端(如 Redis、Memcached)会拒绝非法键名,导致运行时异常;
  • 避免过度依赖 file_get_contents:它不支持超时控制、重试机制与 User-Agent 设置,生产环境建议改用 Guzzle HTTP Client 并启用连接池与中间件;
  • 标题解析应升级为 DOM 解析:正则匹配 HTML 存在严重局限性(如跨行 、CDATA、HTML 实体),推荐使用 DOMDocument:</li></ul><pre class="brush:php;toolbar:false">// 更可靠的标题提取方式(替代 preg_match) $dom = new \DOMDocument(); libxml_use_internal_errors(true); // 抑制加载警告 $dom->loadHTML($pages, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); libxml_clear_errors(); $titleNode = $dom->getElementsByTagName('title')->item(0); return $titleNode ? trim($titleNode->textContent) : null;</pre><p>? <strong>进阶优化建议</strong>:</p><ul><li>为高频调用封装为 Eloquent 访问器或独立服务类,便于测试与复用;</li><li>添加失败降级逻辑(如缓存失效时静默重试一次);</li><li>配合队列 + Laravel Horizon 实现异步预热缓存,避免首次访问延迟;</li><li>对敏感站点设置 User-Agent 头,遵守 robots.txt,必要时加入随机延时防封禁。</li></ul><p>通过将缓存键与输入参数严格绑定,并辅以健壮的 HTTP 与 HTML 处理策略,即可在保障数据准确性的前提下,充分发挥 Laravel 缓存的性能优势。</p><p>文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《Laravel缓存键绑定URL防止内容错乱》文章吧,也可关注golang学习网公众号了解相关技术文章。</p> </div> <div class="labsList"> </div> <div class="cateBox"> <div class="cateItem"> <a href="/article/548337.html" title="JavaScript模块是什么?如何用import和export管理代码?" class="img_box"> <img src="/uploads/20260329/177474782969c880b5b7e37.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="JavaScript模块是什么?如何用import和export管理代码?">JavaScript模块是什么?如何用import和export管理代码? </a> <dl> <dt class="lineOverflow"><a href="/article/548337.html" title="JavaScript模块是什么?如何用import和export管理代码?" class="aBlack">上一篇<i></i></a></dt> <dd class="lineTwoOverflow">JavaScript模块是什么?如何用import和export管理代码?</dd> </dl> </div> <div class="cateItem"> <a href="/article/548339.html" title="图片的alt属性是HTML中用于描述图片内容的文本,当图片无法加载时,会显示该文本。它对SEO和可访问性非常重要,能提升搜索引擎对图片的理解,同时帮助视障用户通过屏幕阅读器了解图片信息。" class="img_box"> <img src="/uploads/20260329/177474788969c880f1be1da.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="图片的alt属性是HTML中用于描述图片内容的文本,当图片无法加载时,会显示该文本。它对SEO和可访问性非常重要,能提升搜索引擎对图片的理解,同时帮助视障用户通过屏幕阅读器了解图片信息。"> </a> <dl> <dt class="lineOverflow"><a href="/article/548339.html" class="aBlack" title="图片的alt属性是HTML中用于描述图片内容的文本,当图片无法加载时,会显示该文本。它对SEO和可访问性非常重要,能提升搜索引擎对图片的理解,同时帮助视障用户通过屏幕阅读器了解图片信息。">下一篇<i></i></a></dt> <dd class="lineTwoOverflow">图片的alt属性是HTML中用于描述图片内容的文本,当图片无法加载时,会显示该文本。它对SEO和可访问性非常重要,能提升搜索引擎对图片的理解,同时帮助视障用户通过屏幕阅读器了解图片信息。</dd> </dl> </div> </div> </div> </div> <div class="leftContBox pt0"> <div class="pdl20"> <div class="contTit"> <a href="/articlelist.html" class="more" title="查看更多">查看更多<i class="iconfont"></i></a> <div class="tit">最新文章</div> </div> </div> <ul class="newArticleList"> <li> <div class="contBox"> <a href="/article/621037.html" class="img_box" title="PHP 8.5 Closure::getCurrent() 递归闭包怎么测:缓存、深度与异常边界"> <img src="/uploads/20260816/1786891755-closure-boundary-checks.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 8.5 Closure::getCurrent() 递归闭包怎么测:缓存、深度与异常边界"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   <a href="/articletag/1433_new_0_1.html" class="aLightGray" title="PHP">PHP</a> · <a href="/articletag/1824_new_0_1.html" class="aLightGray" title="递归">递归</a> · <a href="/articletag/34563_new_0_1.html" class="aLightGray" title="closure">closure</a> · <a href="/articletag/40348_new_0_1.html" class="aLightGray" title="PHP 8.5">PHP 8.5</a> · <a href="/articletag/40507_new_0_1.html" class="aLightGray" title="代码设计">代码设计</a> · <a href="javascript:;" class="aLightGray" title="PHP 8.5">PHP 8.5</a> <a href="javascript:;" class="aLightGray" title="Closure::getCurrent">Closure::getCurrent</a> <a href="javascript:;" class="aLightGray" title="递归闭包">递归闭包</a> <a href="javascript:;" class="aLightGray" title="PHP 闭包">PHP 闭包</a> <a href="javascript:;" class="aLightGray" title="缓存遍历">缓存遍历</a> </span> </dd> <dt class="lineOverflow"> <a href="/article/621037.html" class="aBlack" target="_blank" title="PHP 8.5 Closure::getCurrent() 递归闭包怎么测:缓存、深度与异常边界">PHP 8.5 Closure::getCurrent() 递归闭包怎么测:缓存、深度与异常边界</a> </dt> <dd class="cont2"> <span><i class="view"></i>214浏览</span> <span class="collectBtn user_collection" data-id="621037" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/621025.html" class="img_box" title="PHP 8.5 clone() with 怎么更新 readonly DTO:浅拷贝、嵌套对象与回滚边界"> <img src="/uploads/20260816/1786885496-php-clone-with-shallow.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 8.5 clone() with 怎么更新 readonly DTO:浅拷贝、嵌套对象与回滚边界"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   <a href="/articletag/1433_new_0_1.html" class="aLightGray" title="PHP">PHP</a> · <a href="/articletag/14153_new_0_1.html" class="aLightGray" title="clone">clone</a> · <a href="/articletag/25013_new_0_1.html" class="aLightGray" title="DTO">DTO</a> · <a href="/articletag/40348_new_0_1.html" class="aLightGray" title="PHP 8.5">PHP 8.5</a> · <a href="/articletag/40622_new_0_1.html" class="aLightGray" title="readonly">readonly</a> · <a href="javascript:;" class="aLightGray" title="php">php</a> <a href="javascript:;" class="aLightGray" title="clone">clone</a> <a href="javascript:;" class="aLightGray" title="dto">dto</a> <a href="javascript:;" class="aLightGray" title="不可变对象">不可变对象</a> <a href="javascript:;" class="aLightGray" title="readonly">readonly</a> <a href="javascript:;" class="aLightGray" title="PHP 8.5">PHP 8.5</a> </span> </dd> <dt class="lineOverflow"> <a href="/article/621025.html" class="aBlack" target="_blank" title="PHP 8.5 clone() with 怎么更新 readonly DTO:浅拷贝、嵌套对象与回滚边界">PHP 8.5 clone() with 怎么更新 readonly DTO:浅拷贝、嵌套对象与回滚边界</a> </dt> <dd class="cont2"> <span><i class="view"></i>237浏览</span> <span class="collectBtn user_collection" data-id="621025" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/621003.html" class="img_box" title="PHP 8.5 clone with 怎么改不可变对象:属性覆盖、私有属性与回归检查"> <img src="/uploads/20260816/1786876344-php-clone-with-checks.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 8.5 clone with 怎么改不可变对象:属性覆盖、私有属性与回归检查"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   <a href="/articletag/1433_new_0_1.html" class="aLightGray" title="PHP">PHP</a> · <a href="/articletag/40348_new_0_1.html" class="aLightGray" title="PHP 8.5">PHP 8.5</a> · <a href="/articletag/40607_new_0_1.html" class="aLightGray" title="对象设计">对象设计</a> · <a href="javascript:;" class="aLightGray" title="不可变对象">不可变对象</a> <a href="javascript:;" class="aLightGray" title="PHP 8.5">PHP 8.5</a> <a href="javascript:;" class="aLightGray" title="clone with">clone with</a> </span> </dd> <dt class="lineOverflow"> <a href="/article/621003.html" class="aBlack" target="_blank" title="PHP 8.5 clone with 怎么改不可变对象:属性覆盖、私有属性与回归检查">PHP 8.5 clone with 怎么改不可变对象:属性覆盖、私有属性与回归检查</a> </dt> <dd class="cont2"> <span><i class="view"></i>306浏览</span> <span class="collectBtn user_collection" data-id="621003" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/621002.html" class="img_box" title="PHP 8.5 常量表达式支持静态闭包和一等可调用:属性参数怎么验收"> <img src="/uploads/20260816/1786876021-attribute-version-branch.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 8.5 常量表达式支持静态闭包和一等可调用:属性参数怎么验收"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/621002.html" class="aBlack" target="_blank" title="PHP 8.5 常量表达式支持静态闭包和一等可调用:属性参数怎么验收">PHP 8.5 常量表达式支持静态闭包和一等可调用:属性参数怎么验收</a> </dt> <dd class="cont2"> <span><i class="view"></i>164浏览</span> <span class="collectBtn user_collection" data-id="621002" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/620996.html" class="img_box" title="PHP 弃用 API 发布前怎么做版本验收:8.4/8.5 的 Deprecated、trait 与常量"> <img src="/uploads/20260816/1786873435-php-deprecated-call-chain.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 弃用 API 发布前怎么做版本验收:8.4/8.5 的 Deprecated、trait 与常量"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/620996.html" class="aBlack" target="_blank" title="PHP 弃用 API 发布前怎么做版本验收:8.4/8.5 的 Deprecated、trait 与常量">PHP 弃用 API 发布前怎么做版本验收:8.4/8.5 的 Deprecated、trait 与常量</a> </dt> <dd class="cont2"> <span><i class="view"></i>107浏览</span> <span class="collectBtn user_collection" data-id="620996" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/620995.html" class="img_box" title="PHP 8.5 #[\Deprecated] 怎么标记 trait 和常量:Reflection 验收与兼容边界"> <img src="/uploads/20260816/1786873337-php-deprecated-call-chain.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 8.5 #[\Deprecated] 怎么标记 trait 和常量:Reflection 验收与兼容边界"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/620995.html" class="aBlack" target="_blank" title="PHP 8.5 #[\Deprecated] 怎么标记 trait 和常量:Reflection 验收与兼容边界">PHP 8.5 #[\Deprecated] 怎么标记 trait 和常量:Reflection 验收与兼容边界</a> </dt> <dd class="cont2"> <span><i class="view"></i>239浏览</span> <span class="collectBtn user_collection" data-id="620995" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/620989.html" class="img_box" title="PHP 文件上传 MIME 怎么验:finfo_file、临时文件与扩展名边界"> <img src="/uploads/20260816/1786870895-php-error-handler-call-chain.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 文件上传 MIME 怎么验:finfo_file、临时文件与扩展名边界"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   <a href="/articletag/3_new_0_1.html" class="aLightGray" title="WEB开发">WEB开发</a> · <a href="/articletag/616_new_0_1.html" class="aLightGray" title="文件上传">文件上传</a> · <a href="/articletag/1433_new_0_1.html" class="aLightGray" title="PHP">PHP</a> · <a href="/articletag/40164_new_0_1.html" class="aLightGray" title="安全校验">安全校验</a> · <a href="/articletag/40603_new_0_1.html" class="aLightGray" title="Fileinfo">Fileinfo</a> · <a href="javascript:;" class="aLightGray" title="PHP 文件上传">PHP 文件上传</a> <a href="javascript:;" class="aLightGray" title="move_uploaded_file">move_uploaded_file</a> <a href="javascript:;" class="aLightGray" title="MIME">MIME</a> <a href="javascript:;" class="aLightGray" title="finfo_file">finfo_file</a> <a href="javascript:;" class="aLightGray" title="is_uploaded_file">is_uploaded_file</a> </span> </dd> <dt class="lineOverflow"> <a href="/article/620989.html" class="aBlack" target="_blank" title="PHP 文件上传 MIME 怎么验:finfo_file、临时文件与扩展名边界">PHP 文件上传 MIME 怎么验:finfo_file、临时文件与扩展名边界</a> </dt> <dd class="cont2"> <span><i class="view"></i>117浏览</span> <span class="collectBtn user_collection" data-id="620989" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/620988.html" class="img_box" title="PHP 8.5 get_error_handler 怎么查当前处理器:临时兜底与恢复验证"> <img src="/uploads/20260816/1786870562-php-error-handler-call-chain.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 8.5 get_error_handler 怎么查当前处理器:临时兜底与恢复验证"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   <a href="/articletag/3_new_0_1.html" class="aLightGray" title="WEB开发">WEB开发</a> · <a href="/articletag/503_new_0_1.html" class="aLightGray" title="错误处理">错误处理</a> · <a href="/articletag/1433_new_0_1.html" class="aLightGray" title="PHP">PHP</a> · <a href="/articletag/40348_new_0_1.html" class="aLightGray" title="PHP 8.5">PHP 8.5</a> · <a href="/articletag/40525_new_0_1.html" class="aLightGray" title="异常排查">异常排查</a> · <a href="javascript:;" class="aLightGray" title="set_error_handler">set_error_handler</a> <a href="javascript:;" class="aLightGray" title="PHP 8.5">PHP 8.5</a> <a href="javascript:;" class="aLightGray" title="get_error_handler">get_error_handler</a> <a href="javascript:;" class="aLightGray" title="restore_error_handler">restore_error_handler</a> <a href="javascript:;" class="aLightGray" title="错误处理器">错误处理器</a> </span> </dd> <dt class="lineOverflow"> <a href="/article/620988.html" class="aBlack" target="_blank" title="PHP 8.5 get_error_handler 怎么查当前处理器:临时兜底与恢复验证">PHP 8.5 get_error_handler 怎么查当前处理器:临时兜底与恢复验证</a> </dt> <dd class="cont2"> <span><i class="view"></i>292浏览</span> <span class="collectBtn user_collection" data-id="620988" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/620984.html" class="img_box" title="PHP 8.5 array_last() 非连续键怎么取最后值:空数组与 Polyfill 边界"> <img src="/uploads/20260816/1786868161-php-array-last-null-branch.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 8.5 array_last() 非连续键怎么取最后值:空数组与 Polyfill 边界"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   <a href="/articletag/439_new_0_1.html" class="aLightGray" title="数组">数组</a> · <a href="/articletag/1433_new_0_1.html" class="aLightGray" title="PHP">PHP</a> · <a href="/articletag/40348_new_0_1.html" class="aLightGray" title="PHP 8.5">PHP 8.5</a> · <a href="/articletag/40476_new_0_1.html" class="aLightGray" title="兼容性">兼容性</a> · <a href="javascript:;" class="aLightGray" title="php">php</a> <a href="javascript:;" class="aLightGray" title="数组">数组</a> <a href="javascript:;" class="aLightGray" title="Polyfill">Polyfill</a> <a href="javascript:;" class="aLightGray" title="PHP 8.5">PHP 8.5</a> <a href="javascript:;" class="aLightGray" title="array_last">array_last</a> </span> </dd> <dt class="lineOverflow"> <a href="/article/620984.html" class="aBlack" target="_blank" title="PHP 8.5 array_last() 非连续键怎么取最后值:空数组与 Polyfill 边界">PHP 8.5 array_last() 非连续键怎么取最后值:空数组与 Polyfill 边界</a> </dt> <dd class="cont2"> <span><i class="view"></i>479浏览</span> <span class="collectBtn user_collection" data-id="620984" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/620983.html" class="img_box" title="PHP 8.5 array_last() 怎么处理空数组:从 null 结果到兼容旧版本的 Polyfill"> <img src="/uploads/20260816/1786868006-php-array-last-null-branch.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 8.5 array_last() 怎么处理空数组:从 null 结果到兼容旧版本的 Polyfill"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   <a href="/articletag/439_new_0_1.html" class="aLightGray" title="数组">数组</a> · <a href="/articletag/1433_new_0_1.html" class="aLightGray" title="PHP">PHP</a> · <a href="/articletag/40348_new_0_1.html" class="aLightGray" title="PHP 8.5">PHP 8.5</a> · <a href="/articletag/40476_new_0_1.html" class="aLightGray" title="兼容性">兼容性</a> · <a href="javascript:;" class="aLightGray" title="php">php</a> <a href="javascript:;" class="aLightGray" title="数组">数组</a> <a href="javascript:;" class="aLightGray" title="Polyfill">Polyfill</a> <a href="javascript:;" class="aLightGray" title="PHP 8.5">PHP 8.5</a> <a href="javascript:;" class="aLightGray" title="array_last">array_last</a> </span> </dd> <dt class="lineOverflow"> <a href="/article/620983.html" class="aBlack" target="_blank" title="PHP 8.5 array_last() 怎么处理空数组:从 null 结果到兼容旧版本的 Polyfill">PHP 8.5 array_last() 怎么处理空数组:从 null 结果到兼容旧版本的 Polyfill</a> </dt> <dd class="cont2"> <span><i class="view"></i>501浏览</span> <span class="collectBtn user_collection" data-id="620983" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/620965.html" class="img_box" title="PHP 8.5 URI 扩展怎么替代 parse_url:规范化、相对路径与请求校验"> <img src="/uploads/20260816/1786859089-php-uri-parse-vs-uri.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 8.5 URI 扩展怎么替代 parse_url:规范化、相对路径与请求校验"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1天前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/620965.html" class="aBlack" target="_blank" title="PHP 8.5 URI 扩展怎么替代 parse_url:规范化、相对路径与请求校验">PHP 8.5 URI 扩展怎么替代 parse_url:规范化、相对路径与请求校验</a> </dt> <dd class="cont2"> <span><i class="view"></i>323浏览</span> <span class="collectBtn user_collection" data-id="620965" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/620676.html" class="img_box" title="PHP 8.2 枚举实现后台角色权限:拒绝默认、策略映射与审计日志"> <img src="/uploads/20260809/1786232047-php-enum-role-action.webp" onerror="this.src='/assets/images/moren/morentu.png'" alt="PHP 8.2 枚举实现后台角色权限:拒绝默认、策略映射与审计日志"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/84_new_0_1.html" class="aLightGray" title="php教程">php教程</a>   |  1星期前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/620676.html" class="aBlack" target="_blank" title="PHP 8.2 枚举实现后台角色权限:拒绝默认、策略映射与审计日志">PHP 8.2 枚举实现后台角色权限:拒绝默认、策略映射与审计日志</a> </dt> <dd class="cont2"> <span><i class="view"></i>495浏览</span> <span class="collectBtn user_collection" data-id="620676" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> </ul> </div> </div> <div class="mainRight"> <!-- 右侧广告位banner --> <div class="rightContBox" style="margin-top: 0px;"> <div class="rightTit"> <a href="/courselist.html" class="more" title="查看更多">查看更多<i class="iconfont"></i></a> <div class="tit lineOverflow">课程推荐</div> </div> <ul class="lessonRecomRList"> <li> <a href="/course/9.html" class="img_box" target="_blank" title="前端进阶之JavaScript设计模式"> <img src="/uploads/20221222/52fd0f23a454c71029c2c72d206ed815.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="前端进阶之JavaScript设计模式"> </a> <dl> <dt class="lineTwoOverflow"><a href="/course/9.html" target="_blank" class="aBlack" title="前端进阶之JavaScript设计模式">前端进阶之JavaScript设计模式</a></dt> <dd class="cont1 lineTwoOverflow"> 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。 </dd> <dd class="cont2">543次学习</dd> </dl> </li> <li> <a href="/course/2.html" class="img_box" target="_blank" title="GO语言核心编程课程"> <img src="/uploads/20221221/634ad7404159bfefc6a54a564d437b5f.png" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="GO语言核心编程课程"> </a> <dl> <dt class="lineTwoOverflow"><a href="/course/2.html" target="_blank" class="aBlack" title="GO语言核心编程课程">GO语言核心编程课程</a></dt> <dd class="cont1 lineTwoOverflow"> 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。 </dd> <dd class="cont2">516次学习</dd> </dl> </li> <li> <a href="/course/74.html" class="img_box" target="_blank" title="简单聊聊mysql8与网络通信"> <img src="/uploads/20240103/bad35fe14edbd214bee16f88343ac57c.png" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="简单聊聊mysql8与网络通信"> </a> <dl> <dt class="lineTwoOverflow"><a href="/course/74.html" target="_blank" class="aBlack" title="简单聊聊mysql8与网络通信">简单聊聊mysql8与网络通信</a></dt> <dd class="cont1 lineTwoOverflow"> 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让 </dd> <dd class="cont2">500次学习</dd> </dl> </li> <li> <a href="/course/57.html" class="img_box" target="_blank" title="JavaScript正则表达式基础与实战"> <img src="/uploads/20221226/bbe4083bb3cb0dd135fb02c31c3785fb.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="JavaScript正则表达式基础与实战"> </a> <dl> <dt class="lineTwoOverflow"><a href="/course/57.html" target="_blank" class="aBlack" title="JavaScript正则表达式基础与实战">JavaScript正则表达式基础与实战</a></dt> <dd class="cont1 lineTwoOverflow"> 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。 </dd> <dd class="cont2">487次学习</dd> </dl> </li> <li> <a href="/course/28.html" class="img_box" target="_blank" title="从零制作响应式网站—Grid布局"> <img src="/uploads/20221223/ac110f88206daeab6c0cf38ebf5fe9ed.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="从零制作响应式网站—Grid布局"> </a> <dl> <dt class="lineTwoOverflow"><a href="/course/28.html" target="_blank" class="aBlack" title="从零制作响应式网站—Grid布局">从零制作响应式网站—Grid布局</a></dt> <dd class="cont1 lineTwoOverflow"> 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。 </dd> <dd class="cont2">485次学习</dd> </dl> </li> </ul> </div> <div class="rightContBox"> <div class="rightTit"> <a href="/ai.html" class="more" title="查看更多">查看更多<i class="iconfont"></i></a> <div class="tit lineOverflow">AI推荐</div> </div> <ul class="lessonRecomRList"> <li> <a href="/ai/13109.html" target="_blank" title="ljg-skills - "Prompt之神"李继刚开源的 AI 技能集" class="img_box"> <img src="/uploads/ai/20260616/ljg-skills-icon-8bbe1468e5.png" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="ljg-skills - "Prompt之神"李继刚开源的 AI 技能集" style="object-fit:cover;width:100%;height:100%;"> </a> <dl> <dt class="lineTwoOverflow"><a href="/ai/13109.html" class="aBlack" target="_blank" title="ljg-skills">ljg-skills</a></dt> <dd class="cont1 lineTwoOverflow"> ljg-skills 是李继刚开源的 AI 技能与提示词集合,面向大模型使用者整理了一批可复用的 prompt、角色设定和任务技能模板,适合用于学习提示词设计、搭建个人 AI 工作流和沉淀团队常用智能体能力。 </dd> <dd class="cont2">4943次使用</dd> </dl> </li> <li> <a href="/ai/13108.html" target="_blank" title="MELO音乐 - AI 音乐生成平台,支持多模态创作能力" class="img_box"> <img src="/uploads/ai/20260616/melo-icon-10bf590762.png" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="MELO音乐 - AI 音乐生成平台,支持多模态创作能力" style="object-fit:cover;width:100%;height:100%;"> </a> <dl> <dt class="lineTwoOverflow"><a href="/ai/13108.html" class="aBlack" target="_blank" title="MELO音乐">MELO音乐</a></dt> <dd class="cont1 lineTwoOverflow"> MELO音乐是一站式AI视频与音乐制作助手,对标suno, udio的高品质体验。提供伴奏生成、原创写词、无损导出、哼唱识曲、混音变声等全套音频与短视频编辑工具。无论是流行Kpop、电音说唱、民谣古风、摇滚儿歌还是商用轻音乐,MELO为你免费谱曲,轻松做同款! </dd> <dd class="cont2">4514次使用</dd> </dl> </li> <li> <a href="/ai/13107.html" target="_blank" title="UniScribe - AI 免费在线音视频转文字平台" class="img_box"> <img src="/uploads/ai/20260616/uniscribe-icon-3c88366a15.png" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="UniScribe - AI 免费在线音视频转文字平台" style="object-fit:cover;width:100%;height:100%;"> </a> <dl> <dt class="lineTwoOverflow"><a href="/ai/13107.html" class="aBlack" target="_blank" title="UniScribe">UniScribe</a></dt> <dd class="cont1 lineTwoOverflow"> UniScribe 是一款 AI 音视频转文字与内容整理工具,支持上传音频、视频文件或粘贴 YouTube 链接,自动生成转写文本、摘要、思维导图和关键问题,并支持多格式导出,适合会议记录、课程学习、访谈整理和内容创作复盘。 </dd> <dd class="cont2">4456次使用</dd> </dl> </li> <li> <a href="/ai/13106.html" target="_blank" title="剧云 - 免费 AI 智能中文剧本创作平台" class="img_box"> <img src="/uploads/ai/20260615/d36c7176-icon-2b0cd581ce.png" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="剧云 - 免费 AI 智能中文剧本创作平台" style="object-fit:cover;width:100%;height:100%;"> </a> <dl> <dt class="lineTwoOverflow"><a href="/ai/13106.html" class="aBlack" target="_blank" title="剧云">剧云</a></dt> <dd class="cont1 lineTwoOverflow"> 剧云是专业中文剧本创作平台,安全稳定运行十余年,集成AI编剧、剧本医生审核、人物小传、剧情关系图、大纲编写、多人协作、Word导入导出、版权管控功能,数据安全防护,轻松高效创作剧本。 </dd> <dd class="cont2">4702次使用</dd> </dl> </li> <li> <a href="/ai/13105.html" target="_blank" title="万象有声 - AI 一站式有声内容创作平台" class="img_box"> <img src="/uploads/ai/20260615/50267bac-icon-c146b001b5.png" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="万象有声 - AI 一站式有声内容创作平台" style="object-fit:cover;width:100%;height:100%;"> </a> <dl> <dt class="lineTwoOverflow"><a href="/ai/13105.html" class="aBlack" target="_blank" title="万象有声">万象有声</a></dt> <dd class="cont1 lineTwoOverflow"> 万象有声,一个专为有声创作者打造的新一代智能有声内容创作平台。平台提供专业的智能拆章、智能画本编辑、AI配音、AI生成音效、后期制作、智能对轨、智能审听等有声创作全流程工具,可以帮助创作者高效、低成本创作出引人入胜的有声作品。立即体验,让有声书制作更简单! </dd> <dd class="cont2">4660次使用</dd> </dl> </li> </ul> </div> <!-- 相关文章 --> <div class="rightContBox"> <div class="rightTit"> <a href="/articlelist.html" class="more" title="查看更多">查看更多<i class="iconfont"></i></a> <div class="tit lineOverflow">相关文章</div> </div> <ul class="aboutArticleRList"> <li> <dl> <dt class="lineTwoOverflow"><a href="/article/620983.html" class="aBlack" title="PHP 8.5 array_last() 怎么处理空数组:从 null 结果到兼容旧版本的 Polyfill">PHP 8.5 array_last() 怎么处理空数组:从 null 结果到兼容旧版本的 Polyfill</a></dt> <dd> <span class="left">2026-08-16</span> <span class="right">501浏览</span> </dd> </dl> </li> <li> <dl> <dt class="lineTwoOverflow"><a href="/article/616777.html" class="aBlack" title="宝塔配置Ruby环境:RVM+Nginx反代教程">宝塔配置Ruby环境:RVM+Nginx反代教程</a></dt> <dd> <span class="left">2026-05-29</span> <span class="right">501浏览</span> </dd> </dl> </li> <li> <dl> <dt class="lineTwoOverflow"><a href="/article/616127.html" class="aBlack" title="unset函数作用范围详解">unset函数作用范围详解</a></dt> <dd> <span class="left">2026-05-29</span> <span class="right">501浏览</span> </dd> </dl> </li> <li> <dl> <dt class="lineTwoOverflow"><a href="/article/598283.html" class="aBlack" title="VS Code配置Xdebug教程:PHP调试技巧全解析">VS Code配置Xdebug教程:PHP调试技巧全解析</a></dt> <dd> <span class="left">2026-05-13</span> <span class="right">501浏览</span> </dd> </dl> </li> <li> <dl> <dt class="lineTwoOverflow"><a href="/article/591780.html" class="aBlack" title="PHPEnv安装PhpMyAdmin教程详解">PHPEnv安装PhpMyAdmin教程详解</a></dt> <dd> <span class="left">2026-05-07</span> <span class="right">501浏览</span> </dd> </dl> </li> </ul> </div> </div> </div> <div class="footer"> <div class="footerIn"> <div class="footLeft"> <div class="linkBox"> <a href="/about/1.html" target="_blank" class="aBlack" title="关于我们">关于我们</a> <a href="/about/5.html" target="_blank" class="aBlack" title="免责声明">免责声明</a> <a href="#" class="aBlack" title="意见反馈">意见反馈</a> <a href="/about/2.html" class="aBlack" target="_blank" title="联系我们">联系我们</a> <a href="/send.html" class="aBlack" title="广告合作">内容提交</a> <a href="/manual/go/" target="_blank" class="aBlack" title="手册">手册</a> </div> <div class="footTip">Golang学习网:公益在线Go学习平台,帮助Go学习者快速成长!</div> <div class="shareBox"> <span><i class="qq"></i>技术交流群</span> </div> <div class="copyRight"> Copyright 2023 http://www.17golang.com/ All Rights Reserved | <a href="https://beian.miit.gov.cn/" target="_blank" title="备案">湘ICP备19018815号-4</a> </div> </div> <div class="footRight"> <ul class="encodeList"> <li> <div class="encodeImg"> <img src="/assets/examples/qrcode_for_gh.jpg" alt="Golang学习网"> </div> <div class="tit">关注公众号</div> <div class="tip">Golang学习网</div> </li> <div class="clear"></div> </ul> </div> <div class="clear"></div> </div> </div> <!-- 微信登录弹窗 --> <style> .popupBg .n-error{ color: red; } </style> <div class="popupBg"> <div class="loginBoxBox"> <div class="imgbg"> <img src="/assets/images/leftlogo.jpg" alt=""> </div> <!-- 微信登录 --> <div class="loginInfo encodeLogin" style="display: none;"> <div class="closeIcon" onclick="$('.popupBg').hide();"></div> <div class="changeLoginType cursorPointer create_wxqrcode" onclick="$('.loginInfo').hide();$('.passwordLogin').show();"> <div class="tip">密码登录在这里</div> </div> <div class="encodeInfo"> <div class="tit"><i></i> 微信扫码登录或注册</div> <div class="encodeImg"> <span id="wx_login_qrcode"><img src="/assets/examples/code.png" alt="二维码"></span> <!-- <div class="refreshBox"> <p>二维码失效</p> <button type="button" class="create_wxqrcode">刷新1111</button> </div> --> </div> <div class="tip">打开微信扫一扫,快速登录/注册</div> </div> <div class="beforeLoginTip">登录即同意 <a href="#" class="aBlue" title="用户协议">用户协议</a> 和 <a href="#" class="aBlue" title="隐私政策">隐私政策</a></div> </div> <!-- 密码登录 --> <div class="loginInfo passwordLogin"> <div class="closeIcon" onclick="$('.popupBg').hide();"></div> <div class="changeLoginType cursorPointer create_wxqrcode" onclick="$('.loginInfo').hide();$('.encodeLogin').show();"> <div class="tip">微信登录更方便</div> </div> <div class="passwordInfo"> <ul class="logintabs selfTabMenu"> <li class="selfTabItem loginFormLi curr">密码登录</li> <li class="selfTabItem registerFormBox ">注册账号</li> </ul> <div class="selfTabContBox"> <div class="selfTabCont loginFormBox" style="display: block;"> <form name="form" id="login-form" class="form-vertical form" method="POST" action="/index/user/login"> <input type="hidden" name="url" value="//www.17golang.com/article/548338.html"/> <input type="hidden" name="__token__" value="e6d3f608b2d691fa8ea0a6fd805d5048" /> <div class="form-group" style="height:70px;"> <input class="form-control" id="account" type="text" name="account" value="" data-rule="required" placeholder="邮箱/用户名" autocomplete="off"> </div> <div class="form-group" style="height:70px;"> <input class="form-control" id="password" type="password" name="password" data-rule="required;password" placeholder="密码" autocomplete="off"> </div> <div class="codeBox" style="height:70px;"> <div class="form-group" style="height:70px; width:205px; float: left;"> <input type="text" name="captcha" class="form-control" placeholder="验证码" data-rule="required;length(4)" /> </div> <span class="input-group-btn" style="padding:0;border:none;"> <img src="/captcha.html" width="100" height="45" onclick="this.src = '/captcha.html?r=' + Math.random();"/> </span> </div> <div class="other"> <a href="#" class="forgetPwd aGray" onclick="$('.loginInfo').hide();$('.passwordForget').show();" title="忘记密码">忘记密码</a> </div> <div class="loginBtn mt25"> <button type="submit">登录</button> </div> </form> </div> <div class="selfTabCont registerFormBox" style="display: none;"> <form name="form1" id="register-form" class="form-vertical form" method="POST" action="/index/user/register"> <input type="hidden" name="invite_user_id" value="0"/> <input type="hidden" name="url" value="//www.17golang.com/article/548338.html"/> <input type="hidden" name="__token__" value="e6d3f608b2d691fa8ea0a6fd805d5048" /> <div class="form-group" style="height:70px;"> <input type="text" name="email" id="email2" data-rule="required;email" class="form-control" placeholder="邮箱"> </div> <div class="form-group" style="height:70px;"> <input type="text" id="username" name="username" data-rule="required;username" class="form-control" placeholder="用户名必须3-30个字符"> </div> <div class="form-group" style="height:70px;"> <input type="password" id="password2" name="password" data-rule="required;password" class="form-control" placeholder="密码必须6-30个字符"> </div> <div class="codeBox" style="height:70px;"> <div class="form-group" style="height:70px; width:205px; float: left;"> <input type="text" name="captcha" class="form-control" placeholder="验证码" data-rule="required;length(4)" /> </div> <span class="input-group-btn" style="padding:0;border:none;"> <img src="/captcha.html" width="100" height="45" onclick="this.src = '/captcha.html?r=' + Math.random();"/> </span> </div> <div class="loginBtn"> <button type="submit">注册</button> </div> </form> </div> </div> </div> <div class="beforeLoginTip">登录即同意 <a href="https://www.17golang.com/about/3.html" target="_blank" class="aBlue" title="用户协议">用户协议</a> 和 <a href="https://www.17golang.com/about/4.html" target="_blank" class="aBlue" title="隐私政策">隐私政策</a></div> </div> <!-- 重置密码 --> <div class="loginInfo passwordForget"> <div class="closeIcon" onclick="$('.popupBg').hide();"></div> <div class="returnLogin cursorPointer" onclick="$('.passwordForget').hide();$('.passwordLogin').show();">返回登录</div> <div class="passwordInfo"> <ul class="logintabs selfTabMenu"> <li class="selfTabItem">重置密码</li> </ul> <div class="selfTabContBox"> <div class="selfTabCont"> <form id="resetpwd-form" class="form-horizontal form-layer nice-validator n-default n-bootstrap form" method="POST" action="/api/user/resetpwd.html" novalidate="novalidate"> <div style="height:70px;"> <input type="text" class="form-control" id="email" name="email" value="" placeholder="输入邮箱" aria-invalid="true"> </div> <div class="codeBox" style="height:70px;"> <div class="form-group" style="height:70px; width:205px; float: left;"> <input type="text" name="captcha" class="form-control" placeholder="验证码" /> </div> <span class="input-group-btn" style="padding:0;border:none;"> <a href="javascript:;" class="btn btn-primary btn-captcha cursorPointer" style="background: #2080F8; border-radius: 4px; color: #fff; padding: 12px; position: absolute;" data-url="/api/ems/send.html" data-type="email" data-event="resetpwd">发送验证码</a> </span> </div> <input type="password" class="form-control" id="newpassword" name="newpassword" value="" placeholder="请输入6-18位密码"> <div class="loginBtn mt25"> <button type="submit">重置密码</button> </div> </form> </div> </div> </div> </div> </div> </div> <script src="/assets/js/juejin-theme.js?v=20260613b" defer></script> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?e34c3e8ab31ba35d7e1c48ea8d77315f"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <script src="/assets/js/frontend/common.js"></script> </body> </html>