Table of Contents
python unicode字符串转成中文
php 二进制直接量
php foreach list
PHP ==和隐式转换
== 、switch、in_array 的松比较
javascript Date对象的浏览器兼容性问题
javascript 模拟Object.keys()
javascript数组去重
工具
Sublime Text3 汉化
javascript reduce
jquery插件
0.1+0.2
mysql分解联合查询
字符串中每个字母重复出现的次数
composer
php一维数组 转 多维数组
python中字符串的按位或
python生成斐波拉契数列
php正则匹配
php max/min
NaN
Mysql 用 一张表中的数据更新另一张表的数据
json_encode输出动态javascript
String.fromCharCode

开发拾遗

Jun 20, 2016 pm 12:28 PM

python unicode字符串转成中文

s = 'u6d4bu8bd5u957fu5ea6' s = s.replace('u', '/u') print s.decode('unicode-escape')
Copy after login

php 二进制直接量

$bin = bindec('110011');  $bin = 0b110011;
Copy after login

php foreach list

$arr = [    [1, 2],    [3, 4],];foreach ($arr as list($a, $b)) {    echo $a.$b/n";}
Copy after login

PHP ==和隐式转换

var_dump(md5('240610708') == md5('QNKCDZO'));// true  两个字符串恰好以0e 的科学记数法开头,字符串被隐式转换为浮点数,也就等效于0×10^0var_dump(sha1('aaroZmOk') == sha1('aaK1STfY'));// truevar_dump('0x1234Ab' == '1193131');// true 0x1234Ab转为16进制,php7无此bugvar_dump( 0 == "a" );// truevar_dump( "0" == "a" );// true
Copy after login

== 、switch、in_array 的松比较

// 如果 $name 值为 0,那么它会满足任何一条 caseswitch ($name) {// 使用switch (strval($name)) {    case "danny":        break;    case "eve":        break;}$needle = '1abc'; $haystack = array(1,2,3); var_dump(in_array($needle, $haystack);// true
Copy after login

javascript Date对象的浏览器兼容性问题

// chrome同时支持’-‘和’/’分割日期的时间字符串;safari不支持’-‘分割日期的时间字符串

var arr = "2010-03-15 10:30:00".split(/[- / :]/),    date = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]);
Copy after login

javascript 模拟Object.keys()

function keys(obj){  var a = [];  for(a[a.length] in obj);  return a;}
Copy after login

javascript数组去重

function dedupe(array){    return Array.from(new Set(array));}dedupe([1,1,2,3]) //[1,2,3]
Copy after login

工具

// 命令行提示tldr npm install -g tldr

octotree是一款可为 GitHub 和 GitLab 添加侧边栏文件导航的 Chrome 和 Opera 插件

python下载视频工具

Sublime Text3 汉化

// Package Control:Install Package,输入Chinese,选择ChineseLocalization

javascript reduce

arr = [1,2,3,4,5] arr.reduce(function(a,b){ return a*10+b; });//12345var result = [1, 2, 3, 4, 5].reduce(function(prev, curr, index, array){debugger;    prev.push(curr * 2);    return prev;}, []);console.log(result);//[2, 4, 6, 8, 10]//求最大值var max = arr.reduce(function(pre,cur,inde,arr){return pre>cur?pre:cur;});var arr = [ {name: 'brick1'}, {name: 'brick2'}, {name: 'brick3'} ]function carryBricks(arr){  return arr.reduce(function(prev, current, index, array){    if (index === 0){      return current.name;    }    else if (index === array.length - 1){      return prev + ' & ' + current.name;    }    else {      return prev + ', ' + current.name;    }  }, ''); }//brick11, brick12 & brick13//去重var arr = [1, 3, 1, 'x', 'zz', 'x', false, false];var result = arr.reduce(function(prev, curr, i, array) {    var flag = prev.every(function(value) {        return value !== curr;    });    flag && prev.push(curr);    return prev;}, []);console.log(result);
Copy after login

jquery插件

输入提示自动完成插件 tokeninput

tablesorter表格排序

Date.js执行日期/时间的计算

图片裁剪

日期选择插件pickadate.js

javascript刻度条插件

0.1+0.2

Math.round( (.1+.2)*100)/100; //0.3
Copy after login

mysql分解联合查询

select * from teacher join school on teacher.id = school.idjoin course on teacher.id = course.idwhere course.name= 'english'  分解后 select * from course where name = 'english'select * from  school where course_id = 1select * from teacher where school_id in (1,2,3) 
Copy after login

字符串中每个字母重复出现的次数

 var temp = {};   'abcdaabc'.replace(/(/w{1})/g,function($1){        temp[$1] ? temp[$1]+=1 : temp[$1] = 1;    })    console.log(temp) // {a: 3, b: 2, c: 2, d: 1}
Copy after login

composer

PHP HTTP请求套件

实现 Laravel 模型的无限极分类

php一维数组 转 多维数组

$arr = ['a', 'b', 'c', 'd'];$child = array();$res = [];while($v = array_pop($arr)) {    $res = [$v => $child];    $child = $res;}
Copy after login

python中字符串的按位或

a = "1000111000"b = "1000000001"c = int(a, 2) | int(b, 2)print('{0:b}'.format(c))#1000111001
Copy after login

python生成斐波拉契数列

def fib(max):    n, a, b = 0, 0, 1    while n < max:        print(b)        a, b = b, a + b        n = n + 1    return 'done'
Copy after login

php正则匹配

$str="{a:1,b:2,c:3}"; preg_match_all('/(/w+):(/d+)/', $str, $matches); $arr = array_combine($matches[1], $matches[2]);#['a'=>1,'b'=>2,'c'=>3]
Copy after login

php max/min

max(ceil(-0.5), 0) # -0.0max(0, ceil(-0.5)) # 0
Copy after login

NaN

_.isNaN = function(obj){    return _.isNumber(obj) && obj !==+obj;};
Copy after login

Mysql 用 一张表中的数据更新另一张表的数据

update tableA as ca inner join tableB as cb set ca.thumbs=cb.thumbs where cb.courseid=1;24.php后期静态绑定

class A {   public static function get_self() {     return new self();   }      public static function get_static() {     return new static();   } }    class B extends A {} get_class(B::get_self());//A get_class(B::get_static()) //B get_class(A::get_static());//A
Copy after login

json_encode输出动态javascript

$images = array(  'myself.png' , 'friends.png' , 'colleagues.png' ); $js_code = 'var images = ' . json_encode($images);  echo $js_code; // var images = ["myself.png","friends.png","colleagues.png"]
Copy after login

String.fromCharCode

var regex_num_set = /&#(/d+);/g;var str = "Here is some text: 每日一色|蓝白~"str2 = str.replace(regex_num_set, function(_, $1) {  return String.fromCharCode($1);});//"Here is some text: 每日一色|蓝白~"
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles