欢迎来到 艾瑞可erik 的魔法世界 🧙‍♂️

给我一个需求,还你一个项目——别管它是什么。这就是全栈。

📚 293 篇文章 🏷️ 510 个标签 📂 90 个分类

🔥 最新文章

php超级全局变量

php用了那么久一些基础东西并不是很了解,今天开始就陆陆续续的学习一下。
php中超级全局变量:

  • $GLOBALS 所有全局变量数组
  • $_SERVER 服务器环境变量数组
  • $_GET get传递给脚本的变量数组
  • $_POST post传给脚本的变量数组
  • $_COOKIE cookie变量数组
  • $_FILES 上传文件相关的变量数组
  • $_ENV 环境变量数组
  • $_REQUEST 所有输入用户的变量数组(包括$_GET $_POST $_COOKIE不包括$_FILES) $_SESSION 会话变量数组

PHP Superglobals

I’ve used PHP for so long but don’t really understand some of the basics. Starting today I’ll be studying them one by one.
Superglobals in PHP:

  • $GLOBALS array of all global variables
  • $_SERVER array of server environment variables
  • $_GET array of variables passed to the script via get
  • $_POST array of variables passed to the script via post
  • $_COOKIE array of cookie variables
  • $_FILES array of variables related to file uploads
  • $_ENV array of environment variables
  • $_REQUEST array of all user-input variables (including $_GET $_POST $_COOKIE but not $_FILES) $_SESSION array of session variables

php中if注意事项

最近偶然发现php中if有个自动处理比较的参数

例如

  1. $a=’adasds’; if($a==0){ echo “GGGG”; }else{ echo “KKKK”; } 结果输出 GGGG 这是if判断$a时会检测字符串中最开始有误数字,无数字就返回0 所以返回 GGGG
  2. $a=’55adasds’; if($a==55){ echo “GGGG”; }else{ echo “KKKK”; } 结果 GGGG if判断会检测$a中开头是否有数字,有数字就返回数字,所以结果 GGGG
  3. $a=’ad55asds’;或$a=’adasds55’; if($a==55){ echo “GGGG”; }else{ echo “KKKK”; } 结果 KKKK 说明if判断时检测$a不会检测中间和最后面是否有数字,且结果直接返回0; 综上示例 if判断时如果定义变量是整型就不会出现此问题,如果是字符串就要考虑示例1,2的存在。

Things to Watch Out For with if in PHP

Recently I happened to discover that PHP’s if has an automatically handled parameter for comparisons

For example

  1. $a=’adasds’; if($a==0){ echo “GGGG”; }else{ echo “KKKK”; } The result is GGGG. This is because when if evaluates $a it checks whether there is a number at the very start of the string; if there is no number it returns 0, so the result is GGGG
  2. $a=’55adasds’; if($a==55){ echo “GGGG”; }else{ echo “KKKK”; } The result is GGGG. The if comparison checks whether there is a number at the beginning of $a; if there is a number it returns that number, so the result is GGGG
  3. $a=’ad55asds’; or $a=’adasds55’; if($a==55){ echo “GGGG”; }else{ echo “KKKK”; } The result is KKKK, which shows that when if evaluates $a it does not check whether there is a number in the middle or at the end, and the result simply returns 0; In summary, with if comparisons, if the variable you define is an integer this problem won’t come up, but if it is a string you have to take the situations in examples 1 and 2 into account.

内网穿透、支付接口本地化开发、本地挂网外网访问

在技术qq群偶然聊得最近想入手一台微型服务器,电脑装虚拟机多了感觉好卡,操作不太方便。 群友有提到利用内网穿透不必本地挂载linux服务器便可以很轻松实现。

顺便就查查他们所说的ngrok,百度的解释如下:

看来这是个不错的工具,减少挂载带来的资源占用。

Intranet Penetration, Localized Payment Interface Development, and Hosting Locally with External Access

Chatting casually in a technical QQ group, I mentioned that I’d recently been thinking about getting a mini server, since running too many virtual machines on the computer feels slow and is inconvenient to operate. A group member mentioned that with intranet penetration you can do it very easily without hosting a Linux server locally.

So I looked up the ngrok they were talking about. Baidu’s explanation is as follows:

Looks like this is a pretty good tool — it reduces the resource usage that comes with hosting.

php对接微信支付问题

官方文档比较简略,demo教程基本没参数注释,看代码找吧。
支付 扫码支付 native.php
模式二

$input->SetBody(“test”); //描述

$input->SetAttach(“test”); //订单id 附件自定义数据,会会原样返回

$input->SetGoods_tag(“test”); //代金券或立减优惠功能的参数

$input->SetNotify_url(‘url’); //指定回调地址

$input->SetProduct_id(‘test’); //商户订单号 如果用模式一就要去微信公众平台配置回调地址 ,模式二就不用配置

Problems integrating WeChat Pay with PHP

The official documentation is fairly brief, the demo tutorial basically has no parameter comments, so just read the code and figure it out.
Payment Scan-code payment native.php
Mode 2

$input->SetBody(“test”); //description

$input->SetAttach(“test”); //order id, attachment custom data, which will be returned as-is

$input->SetGoods_tag(“test”); //parameters of the voucher or instant discount feature

$input->SetNotify_url(‘url’); //specify the callback address

$input->SetProduct_id(‘test’); //merchant order number. If you use Mode 1 you have to go configure the callback address on the WeChat official platform; Mode 2 does not need configuration

php中单元测试安装phpunit(win+linux)

要获取 PHPUnit,最简单的方法是下载 PHPUnit 的 PHP 档案包 (PHAR),它将 PHPUnit 所需要的所有必要组件(以及某些可选组件)捆绑在单个文件中:

要使用 PHP档案包(PHAR)需要有 phar 扩展。

要使用 PHAR 的 —self-update 功能需要有 openssl 扩展。

如果启用了 Suhosin 扩展,需要在 php.ini 中允许执行 PHAR:

suhosin.executor.include.whitelist = phar

如果要全局安装 PHAR:

$ wget https://phar.phpunit.de/phpunit.phar
$ chmod +x phpunit.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.

也可以直接使用下载的 PHAR 文件:

$ wget https://phar.phpunit.de/phpunit.phar
$ php phpunit.phar --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.

Windows

整体上说,在 Windows 下安装 PHAR 和手工在 Windows 下安装 Composer 是一样的过程:
  1. 为 PHP 的二进制可执行文件建立一个目录,例如 C:\bin
  2. 将 ;C:\bin 附加到 PATH 环境变量中(相关帮助)
  3. 下载 https://phar.phpunit.de/phpunit.phar 并将文件保存到 C:\bin\phpunit.phar
  4. 打开命令行(例如,按 Windows+R » 输入 cmd » ENTER)
  5. 建立外包覆批处理脚本(最后得到 C:\bin\phpunit.cmd):
    C:\Users\username>cd C:\binC:\bin>echo @php "%~dp0phpunit.phar" %* > phpunit.cmdC:\bin>exit
  6. 新开一个命令行窗口,确认一下可以在任意路径下执行 PHPUnit:
    C:\Users\username>phpunit --versionPHPUnit x.y.z by Sebastian Bergmann and contributors.
phpunit官方中文手册 https://phpunit.de/manual/current/zh_cn/installation.html
下载地址:https://phar.phpunit.de/

Installing PHPUnit for Unit Testing in PHP (win+linux)

The simplest way to get PHPUnit is to download PHPUnit’s PHP Archive (PHAR), which bundles all the necessary components PHPUnit needs (plus some optional ones) into a single file:

To use the PHP Archive (PHAR) you need the phar extension.

To use PHAR’s —self-update feature you need the openssl extension.

If the Suhosin extension is enabled, you need to allow PHAR execution in php.ini:

suhosin.executor.include.whitelist = phar

To install PHAR globally:

$ wget https://phar.phpunit.de/phpunit.phar
$ chmod +x phpunit.phar
$ sudo mv phpunit.phar /usr/local/bin/phpunit
$ phpunit --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.

You can also just use the downloaded PHAR file directly:

$ wget https://phar.phpunit.de/phpunit.phar
$ php phpunit.phar --version
PHPUnit x.y.z by Sebastian Bergmann and contributors.

Windows

Overall, installing PHAR on Windows is the same process as manually installing Composer on Windows:
  1. Create a directory for PHP's binary executable, for example C:\bin
  2. Append ;C:\bin to the PATH environment variable (related help)
  3. Download https://phar.phpunit.de/phpunit.phar and save the file to C:\bin\phpunit.phar
  4. Open a command line (for example, press Windows+R » type cmd » ENTER)
  5. Create an outer wrapper batch script (you end up with C:\bin\phpunit.cmd):
    C:\Users\username>cd C:\binC:\bin>echo @php "%~dp0phpunit.phar" %* > phpunit.cmdC:\bin>exit
  6. Open a new command line window and confirm that you can run PHPUnit from any path:
    C:\Users\username>phpunit --versionPHPUnit x.y.z by Sebastian Bergmann and contributors.
PHPUnit official Chinese manual https://phpunit.de/manual/current/zh_cn/installation.html
Download address: https://phar.phpunit.de/

hadoop2.8.0的部署安装教程

Hadoop部署准备 本地vmware安装 Linux系统家族中 centos7 下载地址http://101.110.118.58/isoredirect.centos.org/centos/7/isos/x86\_64/CentOS-7-x86\_64-Minimal-1611.iso Java对应版本1.8.0_121 Hadoop版本2.8.0下载地址 http://mirror.bit.edu.cn/apache/hadoop/common/ 可以根据自己喜好的版本下载

1.基本配置

首先安装一个centos7并配置好java Java环境配置 我的java安装地址 /usr/java/ jdk1.8.0_121 编辑java环境 vi ~/.bash_profile 添加或修改 export JAVA_HOME=/usr/java/jdk1.8.0_121 export PATH=$JAVA_HOME/bin:$PATH 执行 . ~/.bash_profile 使变量生效

Hadoop 2.8.0 Deployment and Installation Tutorial

Hadoop deployment preparation: install Linux locally under VMware. In the Linux family, the CentOS 7 download address is http://101.110.118.58/isoredirect.centos.org/centos/7/isos/x86\_64/CentOS-7-x86\_64-Minimal-1611.iso The matching Java version is 1.8.0_121 Hadoop version 2.8.0 download address http://mirror.bit.edu.cn/apache/hadoop/common/ you can download whichever version you like

1. Basic configuration

First install a CentOS 7 and get Java configured. Java environment configuration: my Java install location is /usr/java/ jdk1.8.0_121 edit the Java environment with vi ~/.bash_profile, add or modify export JAVA_HOME=/usr/java/jdk1.8.0_121 export PATH=$JAVA_HOME/bin:$PATH then run . ~/.bash_profile to make the variables take effect

PHP数组、函数、字符串的常识

php数组排序

sort()根据数组所包含元素进行升序排列 sort()函数是区分大小写。

所有大写字母都在小写字母后面。

asort()函数和ksort()函数对关联数组排序

例如:$a=array(‘name’=>100,’user’=>200,’title’=>300);

函数asort()是根据数组$a的每个元素值进行排序。在数组$a中元素值为数字。

PHP Basics: Arrays, Functions, and Strings

Sorting PHP arrays

sort() sorts the elements contained in the array in ascending order; the sort() function is case-sensitive.

All uppercase letters come after lowercase letters.

The asort() function and the ksort() function sort associative arrays

For example: $a=array(‘name’=>100,’user’=>200,’title’=>300);

The asort() function sorts by each element value in the array $a. In the array $a the element values are numbers.

PHP算法和递归

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php 
header("Content-Type:text/html;charset=utf-8");

$arr=array(1,12,53,14,5,16,7,18,91,10,11,120); //**冒泡排序** 小数往前放,大数往后放

function getpao($arr) {

$len=count($arr); //设置一个空数组 用来接收冒出来的泡 //该层循环控制 需要冒泡的轮数

for($i=1;$i<$len;$i++) { //该层循环用来控制每轮 冒出一个数 需要比较的次数

for($k=0;$k<$len-$i;$k++) {

if($arr\[$k\]>$arr\[$k+1\]) {

$tmp=$arr\[$k+1\]; $arr\[$k+1\]=$arr\[$k\]; $arr\[$k\]=$tmp;

}

}

}

return $arr;

}

PHP algorithms and recursion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php 
header("Content-Type:text/html;charset=utf-8");

$arr=array(1,12,53,14,5,16,7,18,91,10,11,120); //**Bubble sort** small numbers move to the front, large numbers move to the back

function getpao($arr) {

$len=count($arr); //set up an empty array to receive the bubbles that come up //this loop layer controls how many rounds of bubbling are needed

for($i=1;$i<$len;$i++) { //this loop layer controls how many comparisons are needed for one number to bubble up each round

for($k=0;$k<$len-$i;$k++) {

if($arr\[$k\]>$arr\[$k+1\]) {

$tmp=$arr\[$k+1\]; $arr\[$k+1\]=$arr\[$k\]; $arr\[$k\]=$tmp;

}

}

}

return $arr;

}