H5 learning sentiment 01

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Coder_Hcy/article/details/91041627

h5 In fact, very early attention, the basic line from the start, but the basic is intermittent, no depth, no system. But with the development trend of android,

Gradually have a sense of crisis unemployment. With flutter, RectNative, increasingly popular applet, and more recently Huawei to develop the system. Is not represent the future development of mobile end

Js is to move towards the ultimate core development language?

And require the difference 1.include (four ways to load php file)
the include error level lighter (warning), it will not affect the execution of the code. We met once, executed once
include_once only once
to load the file does not exist, only reported ⚠️

require higher requirements (Fatal error), if an error code is not executed down, met once executed once
require_once only once
Once loaded the file does not exist, it will report a fatal error. The current file is no longer execute down

2. Why do not afford to ignore some of the files, as long as it is submitted to the local repository, they do not ignore these files can submit
3.ps how to configure the MAMP
4. file location
5. Functions
  function body
allows more parameter arguments
parameter can be assigned default values

function Function Name () {

}

6. references by value must be a variable
__FUNCTION__ output function names

7. superglobals
automatically put into this global variable array superglobals's
$ GLOBALS [ 'global variable name'] to access the global variables
function in a way to access the global variables
1.

$a="555555";
function test(){
    global  $a;
    echo  $a;
}
test();
2.
$a="5555551";
function  test(){

    echo  $GLOBALS['a'];
}
test();
8.静态变量,定义在函数内部。

9.可变函数,将函数名赋值给变量,并用变量()的方式调用

function test()
{
    echo "hellow";
}

$a = 'test';
$a();
10.匿名函数

$a=function(){
    echo "hellow111";
};
$a();

(function(){
    echo "hellow2222";
})();
11.闭包函数

use 就是讲外部的局部变量保存在函数内部使用

function  func1(){
    $num=20001;
    $func2=function () use ($num){
        echo $num;
    };

    $func2();
}

func1();
12.伪类型
13.系统函数
print();  返回值是1
date():  print_r(date("Y-m-d,H:i:s"));
mt_rand();随机数
cell();//向上取整
floor();//向下取整
function_exists();//判断函数名是否在内存中存在
14.错误处理
//让浏览器以utf-8的格式解析

header('Content-type:text/html;charset=utf-8');
ini_set('display_errors', '1');//让浏览器显示错误信息
ini_set('error_reporting', E_ALL);
15.抛出异常
trigger_error("errormsg");
E_USER_NOTICE
E_USER_WARNING
E_USER_ERROR
E_USER_DEPRECATED
16.自定义错误处理


/**
 * @param $errNum
 * @param $errMsg
 * @param $errFile
 * @param $errLine
 * @param $errContext
 */

function error_msg($errNum, $errMsg, $errFile, $errLine, $errContext)
{
    //查看当前系统可以看到的错误
    if (!(error_reporting() & $errNum)) {
        return false;
    }
    switch ($errNum) {
        case E_ERROR:
        case E_USER_ERROR:
            echo "在" . $errFile . "文件里的第" . $errLine . "行发生fatal Error,错误信息为:" . $errMsg;
            break;
        case E_WARNING:
        case E_USER_WARNING:
            echo "在" . $errFile . "文件里的第" . $errLine . "行发生Warning,错误信息为:" . $errMsg;
            break;

        case E_NOTICE:
        case E_USER_NOTICE:
            echo "在" . $errFile . "文件里的第" . $errLine . "行发生E_NOTICE,错误信息为:" . $errMsg;
            break;

    }
    return true;
}
//修改错误机制
set_error_handler("error_msg");
$a=10;
echo $a/0;

17.字符串
''
""  变量识别的规则
nowdoc
heredoc
18.字符串处理方法



strlen($a); //拉丁文字符串长度,一个中文三个字节
mb_strlen($str);//获取宽字符的长度,能准确获取中文+英文的真实长度

mb_strlen($a);//字符创长度,指定字符集的时候一个中文一个字节
//数组转字符串

$list = [1, 2, 3,"hcy"];
echo implode($list);
echo implode('^',$list);//以什么连接
//字符串转数组
var_dump(str_split($str,1));//指定长度拆分字符串得到数组

//字符串截取
trim($str);//去除两边的空格
echo substr($str,0,3);//指定截取开始位置和截取字符的个数
$str="6766555";
echo strstr($str,'7');//找到一个字符'7'并往后截取
//字符串查找

$str="hcy2019";
echo strpos($str,'y');//查找字符串首次出现的位置
echo strrpos($str,'y');//查找目标字符在字符串中最后一次出现的位置
$str="hcyy2019";
echo str_replace("hcyy","cmj",$str);//将字符串的某个部分替换成另一个部分组成新的字符串
19.数组  可以存放多个类型

数组的分类:索引数组 和 关联数组(字典)



关联数组
$arr=array('name'=>'hcy2019','age'=>123,'sex'=>'男');
定义数组
$arr=array('hcy','love','cmj','2019');
var_dump($arr);
20.多维数组
21.数组遍历
var_dump(array_keys($arr));  所有的key  array
var_dump(array_values($arr)); 所有的value   array
判断某个key是否存在

var_dump(array_key_exists("name",$arr));
isset($arr['name'])  //变量是否定义
empty($arr['name'])  //当变量未定义或者变量定义了但值为null或者'',0,'0',"0"  ===true  转布尔值的
//一维数组遍历
//foreach ($arr as $key => $value) {
//    echo $key, "  ", $value, "<br>";
//}

//foreach ($arr as $value) {
//
//    foreach ($value as $k=>$v){
//        echo $k, "  ", $v, "<br>";
//    }
//}

for循环

for ($i=0;$i<count($arr);$i++){
    var_dump($arr[$i]);
    echo "<br>";
}
22.排序
冒泡排序的特点:两两相比,每轮都能确定一个数


$arr = array(1, 4, 2, 9, 7, 5, 8,7,1);
function bubble_sort()
{
    global $arr;
    //确定轮数
    //每轮最右边都会确定一位数字
    for ($i = 0; $length = count($arr), $i < $length; $i++) {
        for ($j=0;$j<$length-1-$i;$j++){
            if ($arr[$j]>$arr[$j+1]){
                $temp=$arr[$j+1];
                $arr[$j+1]=$arr[$j];
                $arr[$j]=$temp;
            }
        }
    }

    print_r($arr);
}

bubble_sort();
选择排序,不稳定


function select_sort()
{
    //从小往大排序

    global $arr;

    for ($i = 0; $len = count($arr), $i < $len; $i++) {
        $min_pos = $i;//假设最小元素的位置
        for ($j = $min_pos; $j < $len; $j++) {
            if ($arr[$j] < $arr[$min_pos]) {
                $min_pos = $j;
            }
        }
        //找到最小的那个数的位置了,与假设的位置坐交换
        $temp=$arr[$min_pos];
        $arr[$min_pos]=$arr[$i];
        $arr[$i]=$temp;
    }

    print_r($arr) ;
}

select_sort();
插入排序 ,少量,稳定

22.文件操作
readfile() 函数读取文件,并把它写入输出缓冲。
file_exists($filepath)  判断文件是否存在


文件写入 a+  FILE_APPEND指追加操作

  
      $handle = fopen($filename, "a+");
        $str = fwrite($handle, $userinfo);
        fclose($handle);
file_put_contents($filename, $userinfo, FILE_APPEND);


没有文件可以自动创建文件
sudo chmod -R 777   目标文件夹/文件









23.配置一个虚拟主机
/private/etc/apache2/extra/httpd-vhosts.conf

#加一个虚拟主机
#把任意IP的80端口绑定上

<VirtualHost *:80>
    #一台虚拟主机的根目录
    DocumentRoot "/Users/hcy/PhpstormProjects/MyPHP"
    <Directory "/Users/hcy/PhpstormProjects/MyPHP">
        #开启目录结构浏览(Indexes)和软链接目录访问(FollowSymLinks)
        Options Indexes FollowSymLinks
        #不允许目录内.htaccess 文件覆盖此处配置
        AllowOverride None
        #允许所有人访问该目录
        Require all granted
    </Directory>
    #虚拟主机的域名
    ServerName hcy2019.io
    ServerAlias www.hcy2019.io
    #错误日志目录
    ErrorLog "/Users/hcy/PhpstormProjects/MyPHP/errorlog/hcy2019.io-error_log"
    #自定义日志 common是错误级别
    CustomLog "/Users/hcy/PhpstormProjects/MyPHP/errorlog/hcy2019.io-access_log" common
</VirtualHost>

重启apache

sudo apachectl restart

mac host路径
/private/etc/hosts


24.配置扩展
php.ini打开扩展
phpinfo 查看扩展
查看httpd_config  php.ini的配置路径


25.php repl环境

控制台  php -a


26.时间处理

time();//获取秒
echo date("Y-m-d,H:i:s");; //获取年月日,时分秒
date_default_timezone_set("PRC");//设置时区
//对时间格式化
$time='2019-05-30,15:25';
//先转为时间戳
$timestmp=strtotime($time);
echo  date("Y?m?d===H:i:s",$timestmp);
27.常量
定义后不能被修改,也是临时存放的容器
一般程序的配置信息需要用到常量

define("PI",3.14);

常量不需要$

28.表单处理
可以提交的input   type='submit/image'
<button>提交2</button>  也可以提交 默认type='submit'
1.必须要有form标签
2.指定form标签的action和method属性的属性值
不设置action默认是当前页面
不设置method默认是get
3.表单元素(表单域)必须有name
4.表单中必须有提交方法
$_GET 用于接收get请求地址中提交的数据
$_POST 用于接受请求体中提交的数据,(一般是post提交的参数
$_REQUEST 能接受get/post请求提交的数据

接受和检验

1.校验参数的完整性
持久化
响应

29.get与post的区别
get  的url长度是有限的2000个字符


30.label  的作用
对标签的解释说明
31.文件上传
post请求
enctype  编码类型

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data"></form>

</body>


   $files = $_FILES['avatar'];

    if ($files['error']==0){
        echo '上传成功';
    }

UPLOAD_ERR_OK=0  常量  代表上传成功


error :1   文件上传大小的限制


//将上传的文件的临时目录移动到网站目录下
参数一:临时目录  参数二:网站目录下
move_uploaded_file($files['tmp_name'], '../file/' . $files['name']);
此方法有返回值,判断是否返回成功

文件上传大小的限制
修改php.ini文件下的 upload_max_filesize = 2M














Guess you like

Origin blog.csdn.net/Coder_Hcy/article/details/91041627