Blogger Information
Blog 34
fans 0
comment 0
visits 21937
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
11月18日_php基础:函数与post传值 - 九期线上班
只猫
Original
862 people have browsed it

一、post传值

  1. <?php
  2. //post请求
  3. //使用$_POST数组接收
  4. print_r($_POST);
  5. echo '<br>用户输入的邮箱:'.$_POST['email'];
  6. echo '<br>用户输入的密码:'.$_POST['password'];
  7. ?>
  8. <!DOCTYPE html>
  9. <html lang="en">
  10. <head>
  11. <meta charset="UTF-8">
  12. <title>POST传值</title>
  13. </head>
  14. <body>
  15. <form action="" method="post">
  16. <label for="email">email:</label>
  17. <input type="text" name="email" id="email">
  18. <label for="password">password:</label>
  19. <input type="password" name="password" id="password">
  20. <button>登陆</button>
  21. </form>
  22. </body>
  23. </html>

二、php函数

  1. <?php
  2. //php系统函数
  3. //一、字符串函数
  4. //1.strtolower() 将字符串转换成小写
  5. $a = 'ABcDE';
  6. var_dump(strtolower($a)); //string(5) "abcde"
  7. echo '<br>';
  8. //2.strtoupper()将字符串转换成大写
  9. $string = 'abcdE';
  10. var_dump(strtoupper($string)); //string(5) "ABCDE"
  11. echo '<br>';
  12. //3.strlen() 获取字符串长度
  13. $string1 = 'afuiabceankjfdsa';
  14. var_dump(strlen($string1)); //int(16)
  15. echo '<br>';
  16. //4.trim() 去除字符串首尾空白字符(或其他字符)
  17. $string = " 123123 ";
  18. echo trim($string); //123123
  19. echo '<br>';
  20. var_dump(trim($string)); //string(6) "123123"
  21. echo '<br>';
  22. //5.ltrim() 去除字符串左边的空白字符(或其他字符)
  23. $string = "1234321";
  24. var_dump(ltrim($string,'1')); //string(6) "234321"
  25. echo '<br>';
  26. //6.rtrim() 去除字符串右边的空白字符(或其他字符)
  27. $string = "1234321";
  28. var_dump(rtrim($string,'1')); //string(6) "123432"
  29. echo '<br>';
  30. //7.str_replace() 字符串替换
  31. $string = "123aaa123";
  32. var_dump(str_replace('aaa', '123', $string)); //string(9) "123123123"
  33. echo '<br>';
  34. //8.strpbrk() 字符串中查找一组字符是否存在...
  35. $string = '13701796255';
  36. var_dump(strpbrk($string, '18')); //string(11) "13701796255"
  37. echo '<br>';
  38. //9.explode() 把字符串拆分成数组。
  39. $stringArr = 'a b c d e';
  40. var_dump(explode(' ', $stringArr)); //array(5) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "e" }
  41. echo '<br>';
  42. //10.implode() 把数组组合为字符串。
  43. $array = ['a','b','c','d','e'];
  44. var_dump(implode('', $array)); //string(5) "abcde"
  45. echo '<br>';
  46. //11.md5() 对字符串进行md5加密
  47. $password = '123456';
  48. var_dump(md5($password)); //string(32) "e10adc3949ba59abbe56e057f20f883e"
  49. echo '<br>';
  50. //12.count() 计算数组中元素的数量
  51. $arr = ['1','2','3','4','5'];
  52. var_dump(count($arr)); //int(5)
  53. echo '<br>';
  54. //13.array_merge() 合并两个数组
  55. $arr2 = ['a','b','c'];
  56. var_dump(array_merge($arr,$arr2)); //array(8) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" [3]=> string(1) "4" [4]=> string(1) "5" [5]=> string(1) "a" [6]=> string(1) "b" [7]=> string(1) "c" }
  57. echo '<br>';
  58. //14.in_array() 查询数组中是否存在某值
  59. var_dump(in_array('a', $arr)); //bool(false)
  60. echo '<br>';
  61. var_dump(in_array('a', $arr2)); //bool(true)
  62. echo '<br>';
  63. //15.sort() 数组的升序排序 对索引数组 成功返回1 失败返回0
  64. $arr_sort = ['16','25','32','12.5'];
  65. sort($arr_sort);
  66. print_r($arr_sort); //Array ( [0] => 12.5 [1] => 16 [2] => 25 [3] => 32 )
  67. echo '<br>';
  68. //16.rsort() 数组的降序排序
  69. rsort($arr_sort);
  70. print_r($arr_sort); //Array ( [0] => 32 [1] => 25 [2] => 16 [3] => 12.5 )
  71. echo '<br>';
  72. //17.array_unique() 移除数组中重复的值 去除之后下标保持不变
  73. $array = ['6','6','6','5','4'];
  74. $array_unique=array_unique($array);
  75. print_r($array_unique); //Array ( [0] => 6 [3] => 5 [4] => 4 )
  76. echo '<br>';
  77. //18.array_push() 将元素添加到数组的末尾 返回添加后的数组长度
  78. array_push($array,'3','2','1');
  79. print_r($array); //Array ( [0] => 6 [1] => 6 [2] => 6 [3] => 5 [4] => 4 [5] => 3 [6] => 2 [7] => 1 )
  80. echo '<br>';
  81. //19.array_pop() 将数组末尾最后一个元素移除 返回被删除元素
  82. array_pop($array);
  83. print_r($array); //Array ( [0] => 6 [1] => 6 [2] => 6 [3] => 5 [4] => 4 [5] => 3 [6] => 2 )
  84. echo '<br>';
  85. //20.array_shift() 删除数组开头的元素
  86. array_shift($array);
  87. print_r($array);
  88. echo '<br>';
  89. //21.array_unshift() 将元素添加到数组开头
  90. array_unshift($array, '0');
  91. print_r($array); //Array ( [0] => 0 [1] => 6 [2] => 6 [3] => 5 [4] => 4 [5] => 3 [6] => 2 )

手写:

总结:php中函数有很大作用,需要能灵活运用处理解决问题。函数众多,记是记不完也记不住的,功能具体分为几大类,可以按照功能分类记住一些常用的以提高开发效率。

Correcting teacher:查无此人查无此人

Correction status:qualified

Teacher's comments:完成的不错,继续努力
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post