收集、管理和分享有用的代码片段,提高开发效率
高效插入多条数据
<?php
$mysqli->real_query("INSERT INTO users (name, email) VALUES ('John', 'john@example.com'), ('Jane', 'jane@example.com')");
强制文件下载
<?php
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="download.pdf"');
readfile('document.pdf');
递归计算目录总大小
<?php
function getDirSize($dir) {
$size = 0;
$files = scandir($dir);
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
$filepath = $dir . '/' . $file;
$size += is_dir($filepath) ? getDirSize($filepath) : filesize($filepath);
}
}
return $size;
}
反转单链表
<?php
class ListNode {
public $data;
public $next = null;
public function __construct($data) {
$this->data = $data;
}
}
function reverseList(&$head) {
$prev = null;
$curr = $head;
while ($curr != null) {
$next = $curr->next;
$curr->next = $prev;
$prev = $curr;
$curr = $next;
}
$head = $prev;
}
连接SQLite数据库
<?php
$db = new SQLite3('mydb.sqlite');
$db->exec('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)');
设置缓存控制头
<?php
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Expires: Thu, 01 Jan 1970 00:00:01 GMT');
高效管理您的代码片段,提高开发效率
通过关键字、语言或分类快速查找代码片段,支持模糊搜索和过滤功能
支持多种编程语言的语法高亮,使代码更加清晰易读
随时随地访问您的代码片段库,支持桌面和移动设备
浏览最受欢迎的代码分类