php实现短网址的原理及示例代码

<?php // 生成随机字符串作为短网址 function generateRandomString($length = 6) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLe...

HTML meta 标签的使用方式总结

介绍 meta 标签的常规使用以及使用 meat 标签设置页面的缓存效果; 提升前端开发同学对请求过程中的缓存认识与设置 。 废话不多说, 直接上代码。 一: meta 标签的使用和总结: <meta> 元素可提供有关页面的 元信息(meta-information), 比如针对 搜索引擎 和 更新频度 的描述和关键词 。 <meta> 标签位于文档的头部, 不包含任何内容 。 <meta> 标签的属性定义了与文档相关联的 名称/值对 。 1. 声明文档使用的 字符编码 声明文档使用的 字符编码 <meta charset='utf-8'> 2...

php替换掉php文件内的自定义方法

今天有个小朋友问了我这么个问题,哈哈,竟然还有这总需求,好吧! <?php $file_content = file_get_contents('test.php'); $pattern = '#function\s+test\s*\(\s*\)\s*\{[^\}]+\}#'; $file_content = preg_replace($pattern, 'function test(){ return "bbb"; }', $file_content); file_put_contents('test.php', $file_content); ?> ...

php实现短网址的基本功能

<!--?php // 连接数据库 $conn = new mysqli('localhost', 'username', 'password', 'database'); // 检查连接 if ($conn--->connect_error) { die("连接失败: " . $conn->connect_error); } // 表单提交检查 if (isset($_POST['submit'])) { // 获取表单数据 $long_url = $_POST['long_url']; // 生成短网址 $short_url = substr(md5($long_url...

php+txt实现的短网址功能,自用足够

<?php // 表单提交 if(isset($_POST['url'])){ // 获取长网址 $long_url = $_POST['url']; // 生成短网址 $short_url = get_short_url($long_url); // 保存短网址 save_short_url($long_url, $short_url); // 输出短网址 echo $short_url; } // 生成短网址 function get_short_url($long_url){ // 生成6位随机码 $code = get_rand_str(6); // 生成短网址 $short_...

php采集某个网页的内容,并把图片本地化

<?php // 获取网页标题和内容 $url = 'http://www.example.com'; $html = file_get_contents($url); $title = preg_match('/<title>(.*?)<\/title>/', $html, $matches); $title = $matches[1]; $content = preg_match('/<div id="content">(.*?)<\/div>/', $html, $matches); $content = $matches[1]; ...

Linux系统 message日志出现“entered promiscuous mode”和“left promiscuous mode”信息

问题描述 Linux系统的ECS实例message日志中出现如下信息。 entered promiscuous mode left promiscuous mode    解决方案   根据日志信息判断,报错并不是异常的错误日志,对服务器系统没有影响。   “device eth0 entered promiscuous mode” ,指eth0网卡进入了混杂模式。   “device eth0 left promiscuous mode” ,指eth0网卡退出了混杂模式。   混杂模式是网卡的一种工作模式,一般在抓取网卡数据包时使用。系统日志里出现这个日志信息,说明在服务器上对网卡进行过抓...

卸载阿里云的监控服务脚本shell

#!/bin/bash #===================================== # Script: Uninstall-aliyun-service-2022 # Version: 1.0.0 # Author: Babywbx & imxiaoanag # Blog: https://imxiaoanag.com/?p=29 #===================================== export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # 检查是否为...

php字符串的一种加密解密算法

<?php function encode($str) { $len = strlen($str); $result = ''; for ($i = 0; $i < $len; $i++) { $temp = ord($str[$i]); if ($temp > 64 && $temp < 91) { $temp = $temp + 16; if ($temp > 90) { $temp = $temp - 26; } } else if ($temp > 96 && $temp < 123) { $temp = $t...