Categories


Tags


21个实用PHP代码

1.连接MySQL: $link=mysqli_connect("localhost","username","password","dbname"); 2.从MySQL中取出数据: $res=mysqli_query($link,"SELECT * FROM tablename"); 3.以数组形式取出数据: while ($row = mysqli_fetch_array($res)) { $data[]=$row; } 4.从MySQL中删除记录: $res=mysqli_query($link,"DELETE FROM tablename WHERE id=1"); 5.向MySQL中插入记录: $res=mysqli_query($link,"INSERT INTO tablename(column1,column2) VALUES('value1','value2')"); 6.关闭MySQL连接: mysqli_close($link); 7.计算两点间的距离: $distance=6371.07*acos(sin($point1Lat)*sin($point2Lat)+cos($point1Lat)*cos($point2Lat)*cos($point1Lng-$point2Lng)); // 6371.07 - 地球半径 8.获取当前时间戳: $timestamp=strtotime("now"); 9.将时间戳转换为格式化的时间: $formated_time=date("m-d-Y @ H:i:s",$timestamp); 10.计算两个日期之间的时间差: $date_diff=strtotime($end_date)-strtotime($start_date);//返回时间差,单位为秒 11.在PHP中获取输入变量: $var=isset($_GET['var_name']) ? $_GET['var_name'] : ''; 12.又比较两个字符串: if(strcmp($str1,$str2)==0) { //字符串相等 echo "Strings are equal."; } 13.生成随机的数字: $random_number=rand(1,100); 14.计算字符串长度: $length=strlen($string); 15.将字符串中特定的字符替换: $string=str_replace("old_str","new_str",$string); 16.获取网页源代码: $data=file_get_contents("http://www.example.com/"); 17.发送邮件: $to="example@example.com"; $subject="Email Subject"; $message="Email message"; $header="From:example@example.com"; mail($to,$subject,$message,$header); 18.加密字符串: $encrypted_string=md5($string); 19.压缩数组: $compressed_array=gzcompress(serialize($array)); 20.解压缩: $array=unserialize(gzuncompress($compressed_array)); 21.在字符串中搜索子字符串: if(strpos($string,"substring")!==false) echo "Substring found in string.";

Public @ 2023-02-25 08:54:40

前端开发大众手册(包括工具、网址、经验等)

一直觉得前端开发缺个手册,这是个体力活。不过总得有人来干。今天闲来无事,把一些工具(online和client的)、常用网址、以及经验总结等罗列出来和大家分享下。这个标题起地大了点,肯定会有很多地方没列到,包括类目的分法也可能考虑不周,所以还请大家积极补充指正,可以直接留言,也可以发邮件给我(sorrycc#gmail.com)。之所以加上“大众”两字,因为以下资源对于高手来说可能早就很熟悉了。另

Public @ 2010-04-21 15:45:14

VPS/云主机/独立服务器 ASP.NET 环境设置

ASP.NET环境设置步骤如下: 1. 安装IIS和ASP.NET模块。 2. 在IIS中创建一个网站,将其绑定到特定的主机名或IP地址。 3. 配置网站的基础设置,包括身份验证和访问控制等。 4. 在网站上添加应用程序池,并为每个ASP.NET应用程序分配一个应用程序池。 5. 为应用程序池配置正确的.NET Framework版本和相应的IIS集成模式。 6. 配置应用程序池可以访

Public @ 2023-06-12 00:50:20

更多您感兴趣的搜索

0.518881s