当前位置: 首页 > news >正文

php 1

Thanks Tutorial!

powered by gpt5-mini in VSCode.

注释比较魔怔

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>*{font-family : "fira code"}.t1{color : #114514}</style> 
</head>
<body><div class="t1">我是 php 的大象</div><?php echo "丁飞说"; ?><!-- php could cooperate as this with html --><!-- now in html env. --><?php if(0) {?><p>   how? </p><?php }?><?php$int = 67; $bool = false;$string = "string";$double = 67.67;/*  default0 false "" 0.0 */// whatDoesThisMean? it means rules in naming;$num = array(7,3,3,5,7,7,3,3);?><br><?php$a = "ding";$b="fei";$c=$a.$b;echo $c;echo "\n";$c=2;$d="3";if($c < $d and $a != $b)echo "eq!";$f=442;/* superglobal variables_GET["name"] // handle data in url _POST["number1"] // handle data in form_REQUEST // not commonly usedhtmlspecialchars()  // prevent xss attack _SERVER['PHP_SELF'] // the file name of currently executing script_SERVER['SERVER_NAME'] // the name of the server host_SERVER['REQUEST_METHOD'] // the request method used to access the page,check if it is POST or GET,prevent form resubmission.header() // redirect to another page*/// switch uses == logi to compare;// !! use "break;" to prevent ub;switch ($f) {case 1:echo "f is 0\n";echo "try\n";break;case "0":echo "how\n";// break;default:echo "nothing";break;}// if this doesnt enter any case // it willnot cause any problems whenever "default" exist or not;// new things in php  match!// !! it uses === logi$g=1;// $g=3;$result = match($g){1 => "g is 1",2,4,6,8 => "g is even",default => "ok well no",};/* if "match" doesnt matched anything it will throw an error to the web!! and shut down the whole program belowwhen "default" doesnt exist; */// slightly different!// both above dont supp. < = > these?><br><?phpecho "no!!";$fruits = ["pineapple","apple","banana"];  //一维数组$fruitsTwo[] = ["pineapple","apple","banana"]; // 二维数组echo $fruits[1];array_push($fruits,"grape"); // 添加元素到结尾$fruits[] = "grape"; // 也可以这样添加元素到结尾$fruits[1] = "grape"; // 修改元素// unset($fruits[1]); // 删除元素echo "<br>";count($fruits); // 获取数组长度for($i=0;$i<count($fruits);$i++){echo $fruits[$i]; echo " ";}array_splice($fruits, 0,1); // 删除元素并重新索引,0表示从第一个元素开始,1表示删除一个元素echo "<br>";echo $fruits[1]; // 输出 grapeecho "<br>";echo "<br>";for($i=0;$i<count($fruits);$i++){echo $fruits[$i]; echo " ";}/* --  associative array  -- */$dingFei = ["father" => "dingFei","son" => "DXJ","wife" => "for sure not apple",];// associative arrayecho "<br>";echo $dingFei["son"];// like map in cpp $dingFei["son"] = "not DXJ"; // modify$dingFei["mother"] = "pineapple"; // add new key-value pair$dingFei["wife"] = null; // set value to nullecho "<br>";  print_r($fruits); // print the whole array in a human-readable formatecho "<br>";print_r($dingFei);count($dingFei); // get the number of elements in the arraysort($dingFei); // turn the associative array into a indexed array and sort it by value// !! this will lose the key-value relationship// instead:// asort($dingFei);  sort associative array by value// ksort($dingFei);  sort associative array by keyarray_splice($fruits,1,0,"watermelon"); // insert "watermelon" at index 1array_splice($fruits,2,0,["peach","pear"]); // insert multiple elements at index 2echo "<br>";print_r($fruits);// multidimensional array$foodNormal = [["pineapple","apple","banana"],["carrot","broccoli","spinach"],["chicken","beef","pork"],];$foodAssociative = ["fruits" => ["pineapple","apple","banana"],"vegetables" => ["carrot","broccoli","spinach"],"meats" => ["chicken","beef","pork"],];$foodAssociativeAssociative = ["fruits" => ["bitter" => "lemon", "sweet" => "banana",],"vegetables" => ["leafy" => "spinach", "root" => "carrot",],];echo $foodAssociativeAssociative["fruits"]["sweet"]; // banana// string functions$stringExample = "Hello, World!";strlen($stringExample); // 获取字符串长度,.size() 不行 $stringExample[7]; // 访问字符串中的字符,类似数组访问 -> 'W'strpos($stringExample, "World"); // 查找子字符(串)的位置,第一个字符位置 -> 7$replaceString = str_replace("World", "PHP", $stringExample); // 替换子字符(串) -> "Hello, PHP!",//!!不改变原字符串,需要接受返回值,函数大多都是这样echo "<br>";echo $stringExample;echo "<br>";echo $replaceString;$loweredString = strtolower($stringExample); // 转为小写 -> "hello, world!"$upperedString = strtoupper($stringExample); // 转为大写 -> "HELLO, WORLD!"$stringExample2 = "114514";$intFromString = intval($stringExample2); // 字符串转整数 -> 114514// "Hello, World!"// 负数语义:倒数第x个字符$subString = substr($stringExample, 7, 5); // 获取子字符串 -> "World",从索引7开始,长度为5$subString2 = substr($stringExample, -6, 5); // 从从倒数第6个字符开始,向后5个字符 -> "World",$subString3 = substr($stringExample, 7, -3); // 从索引7开始,获取到(不包括)倒数第3个字符 -> "Wor" echo $subString2;echo "<br>";echo $subString3;$errorString = substr($stringExample, 20, 5); //!! 索引超出字符串长度,返回空字符串 -> ""echo "<br>";echo $errorString; // 输出空字符串echo "<br>";echo "nothing above";$dividedString = explode(", ", $stringExample); // 将字符串按指定分隔符分割成数组 -> ["Hello", "World!"]echo "<br>";print_r($dividedString);$stringExample2="big      banana";$dividedString2 = explode(" ", $stringExample2); // -> ["big", "", "", "", "", "banana"],多个连续的分隔符会产生空字符串元素echo "<br>";print_r($dividedString2);// mathmatical functions// 同样不改变原变量,需要接受返回值$number = 3.14159;$roundedNumber = round($number, 2); // 四舍五入到小数点后2位 -> 3.14$flooredNumber = floor($number); // 向下取整 -> 3$ceiledNumber = ceil($number); // 向上取整 -> 4$randomNumber = rand(1, 100); // 生成1到100之间的随机整数$power = pow(2, 3); // 计算2的3次方 -> 8$squareRoot = sqrt(16); // 计算16的平方根 -> 4$number2 = -3.14159;$abs = abs($number2); // 计算绝对值 -> 3.14159// array functions$animals = ["cat", "dog", "bird"];$count = count($animals); // 获取数组长度 -> 3$isArray = is_array($animals); // 检查变量是否是数组 -> truearray_push($animals, "fish"); // 在数组末尾添加元素 -> ["cat", "dog", "bird", "fish"]$removedElement = array_pop($animals); // 删除并返回数组末尾的元素 -> "fish" -> ["cat", "dog", "bird"]echo "<br>";print_r($animals);$reversedAnimals = array_reverse($animals); // 反转数组顺序,不改变原数组 -> ["bird", "dog", "cat"]//$animals = array_reverse($animals); // 如果想改变原数组,可以重新赋值echo "<br>";print_r($reversedAnimals);$animalsWithWater = array_merge($animals, ["fish", "frog"]); // 合并数组,加最后面 -> ["cat", "dog", "bird", "fish", "frog"]// time and date functions//UTC 时间和本地时间的转换date_default_timezone_set("Asia/Shanghai"); // 设置默认时区为北京时间(UTC+8)$currentTimestamp = time(); // 获取当前时间戳(自1970年1月1日以来的秒数)$formattedDate = date("Y-m-d H:i:s", $currentTimestamp); // 格式化时间戳为可读日期时间字符串 $formattedDateNow = date("Y-m-d H:i:s"); // 如果不传入时间戳,默认使用当前时间// Y 4位年 m 2位月 d 2位日 H 24小时制小时 i 分钟 s 秒,其它字符保持不变echo "<br>";echo $formattedDateNow;$time1 = "2024-01-01 12:00:00";$stringTimestamp = strtotime($time1); // 将日期时间字符串转换为时间戳echo "<br>";echo $stringTimestamp;?></body>
</html>
http://www.jsqmd.com/news/374961/

相关文章:

  • 极萌美容仪怎么样?科研加持安全又高效 - 博客万
  • 2026年全国二手中央空调回收厂家权威榜单 实力靠谱高效 适配工业等多场景资源再生 - 深度智识库
  • 2026年全国商用设备回收厂家哪家权威?专精多品类 服务响应高效 覆盖全国多区域 - 深度智识库
  • 【opencode】opencode安装使用
  • 2026年权威推荐:卡卡音响引领西南音视频智能化新趋势 - 深度智识库
  • Java计算机毕设之:基于springboot的老年一站式服务平台基于springboot的养老一站式服务系统(完整前后端代码+说明文档+LW,调试定制等)
  • html css js 1
  • 我们的一体化年度服务怎么做:带电池产品从出运到欧盟合规的“交付清单”公开
  • netty学习
  • Java毕设项目推荐-基于SpringBoot的社区养老服务系统设计与实现基于springboot的安心养老一站通服务系统的设计与实现【附源码+文档,调试定制服务】
  • 目标检测数据集 - 太空超新星探测检测数据集下载
  • Java毕设选题推荐:基于springboot的养老一站式服务系统在线预约服务上门护理、康复治疗、日间照料等服务【附源码、mysql、文档、调试+代码讲解+全bao等】
  • 2026年陕西环保装修公司排名:状元郎装饰领衔新房别墅装修与全屋装修设计典范 - 深度智识库
  • 登录认证,验证码实现逻辑
  • 计算机Java毕设实战-基于springboot+vue的老年一站式服务平台基于springboot的养老一站式服务系统【完整源码+LW+部署说明+演示视频,全bao一条龙等】
  • 2.12假期记录
  • 【课程设计/毕业设计】基于springboot的智慧养老综合服务平台 一站式养老服务管理系统【附源码、数据库、万字文档】
  • 函数计算AgentRun重磅上线知识库功能,赋能智能体更“懂”你
  • 性能提升 4 倍的背后:时序数据库 IoTDB 系统调优方法与五个真实案例
  • 2026年电商AI客服品牌权威盘点与避坑指南:抖音/天猫/拼多多商家如何选择? - 深度智识库
  • 花最少的钱降最多的AI率,2026年性价比最高的降AI工具推荐
  • 智能合约自毁:当资产还在,合约死了 —— 深度解析 selfdestruct 导致的资产锁定风险 - 若
  • 【AI应用开发工程师】-长期 AI 编程后,我发现 AI 带来的最大提效竟然是…
  • 2026年2月WPC格栅生产厂家TOP10排行榜:优质供应商环保、专利等综合实力解析 - 品牌推荐2026
  • 手握JBL代理与多项一级资质,卡卡音响凭硬核实力领跑行业 - 深度智识库
  • 2026年盘点口碑好的深圳短视频拍摄公司,哪家几家比较好? - 界川
  • 【毕业设计】基于springboot的校园共享电动自行车管理系统(源码+文档+远程调试,全bao定制等)
  • 【计算机毕业设计案例】基于SpringBoot的地区文创产品销售系统基于springboot的文创销售管理系统(程序+文档+讲解+定制)
  • 2026年2月雪弗板生产厂家TOP10排行榜:优质供应商环保、专利等综合实力解析 - 品牌推荐2026
  • MNF变换在MATLAB中的实现:高维数据降维与特征提取