mysql,php,redis,jq小记

学习笔记

lamp:linux+Apache+mysql+php
mysql的相关内容(基础):
建库

create database 库名;

选择库

use 库名;

查看其它库

show databases;

建表

CREATE TABLE `t_article` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ititleid` int(10) NOT NULL,
  `tcontent` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

查询(多表连查)+索引(复合索引)

select * from table1 left join table2 on table1.id = table2.iid where 筛选条件;
create index 索引名 on table(字段1,字段2...);

删除索引

DROP INDEX 索引名 ON 表名;

添加字段

ALTER  TABLE 表名 ADD  INDEX  索引名 ( 字段名(长度) ) ;

update 表名 set 要改变的值  where 筛选条件 ;

insert into 表名 (字段1,字段2,字段3) values(1,值2,值3);

删记录

delete from 表名 where 筛选条件;

删库

drop database if exists 库名;

删表

drop table if exists 表名;

视图

CREATE VIEW <视图名> AS <SELECT语句>

改字段

alter table 表名 modify column 字段名 类型;

事物

开启事务:Start Transaction
事务结束:End Transaction
提交事务:Commit Transaction
回滚事务:Rollback Transaction

和事务相关的两条重要的SQL语句(TCL)

commit:提交
rollback:回滚

字段类型

tinyint:占用1个sss字节,相对于java中的byte
smallint:占用2个字节,相对于java中的short
int:占用4个字节,相对于java中的int
bigint:占用8个字节,相对于java中的long
float4字节单精度浮点类型,相对于java中的float
double8字节双精度浮点类型,相对于java中的double

(索引和查询优化)优化+分表等+日常小知识+存储引擎
以下是常用sql关键字的优先级

from > where > group by > having > order by

php的相关内容(基础):
时间的方法


// 检查一些日期是否是有效的格利高里日期:
var_dump(checkdate(12,31,-400));
echo "
"
; var_dump(checkdate(2,29,2003)); echo "
"
; var_dump(checkdate(2,29,2004)); // bool(false) // bool(false) // bool(true) //======================================== //添加 100 天到 1980 年 10 月 15 日: $date = date_create("1995-10-15"); date_add($date,date_interval_create_from_date_string("100 days")); echo date_format($date,"Y-m-d"); //1996-01-23 //======================================== //返回一个根据指定格式进行格式化的新的 DateTime 对象: $date=date_create_from_format("j-M-Y","25-Sep-2016"); echo date_format($date,"Y/m/d"); //2016/09/25 //时间就用date或者date_format输出,echo与print是不好用的 //其次date_create_from_format的里面的字母要大写 //======================================== //返回一个新的 DateTime 对象,然后格式化日期: $date = date_create("2016-09-25"); echo date_format($date,"y/m/d"); //16/09/25 //======================================== //返回一个新的 DateTime 对象,设置一个新的日期,然后格式化该日期: $date = date_create(); date_date_set($date,2020,10,15); echo date_format($date,"y/m/d"); //20/10/15 //======================================== //返回默认时区: echo date_default_timezone_get(); //Asia/Shanghai //======================================== //设置默认时区 date_default_timezone_set("Asia/Shanghai"); echo date_default_timezone_get(); //Asia/Shanghai //======================================== //计算两个日期间的差值: $date1 = date_create("1984-01-28"); $date2 = date_create("1980-10-15"); $diff = date_diff($date1,$date2); print_r($diff); //DateInterval Object ( [y] => 3 [m] => 3 [d] => 13 [h] => 0 [i] => 0 [s] => 0 [f] => 0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 1200 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 ) echo '
'
; echo $diff->format("%R%a days"); //-1200 days //======================================== //返回一个新的 DateTime 对象,然后格式化该日期 $date = date_create("2016-12-15"); echo date_format($date,"y/m/d H:i:s"); //16/12/15 00:00:00 //======================================== //返回解析日期字符串时的警告和错误: date_create("aecubdjpoi%&&/"); print_r(date_get_last_errors()); //Array ( [warning_count] => 1 [warnings] => Array ( [6] => Double timezone specification ) [error_count] => 5 [errors] => Array ( [0] => The timezone could not be found in the database [10] => Unexpected character [11] => Unexpected character [12] => Unexpected character [13] => Unexpected character ) ) //======================================== //计算两个日期间的间隔,然后格式化时间间隔: $date1 = date_create("1984-01-01"); $date2 = date_create("1980-10-10"); $diff = date_diff($date1,$date2); echo $diff->format("总天数:%a."); //总天数:1178. /* % - Literal % Y - 年,至少 2 个数字,带前导零(例如 03) y - 年(例如 3) M - 月,带前导零(例如 06) m - 月(例如 6) D - 日,带前导零(例如 09) d - 日(例如 9) a - 由 date_diff() 得出的两个日期间隔的总天数 H - 小时,带前导零(例如 08、23) h - 小时(例如 8、23) I - 分,带前导零(例如 08、23) i - 分(例如 8、23) S - 秒,带前导零(例如 08、23) s - 秒(例如 8、23) R - 当负数时为符号 "-",当正数时为符号 "+" r - 当负数时为符号 "-",当正数时为空 */ //上面有一个例子 //======================================== //设置 2016 年第 5 周的 ISO 日期: $date = date_create(); date_isodate_set($date,2016,5); echo date_format($date,"y-m-d"); //16-02-01 //======================================== //修改时间戳。增加 15 天 $date = date_create("2016-09-25"); date_modify($date,"+4 days"); echo date_format($date,"y-m-d"); //16-09-29 //======================================== //返回纽约的冬天和夏天相对于 UTC 的以秒计的时区偏移量 $winter = date_create("2016-10-15",timezone_open("America/New_York")); $summer = date_create("2016-01-28",timezone_open("America/New_York")); echo date_offset_get($winter)."秒。
"
; echo date_offset_get($summer)."秒。"; // -14400秒。 // -18000秒。 //======================================== //根据指定的格式返回一个包含指定日期信息的关联数组 print_r(date_parse_from_format("mmddyy","05122013")); //Array ( [year] => [month] => 12 [day] => 13 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 1 [errors] => Array ( [8] => Data missing ) [is_localtime] => //======================================== //返回一个包含指定日期的详细信息的关联数组 print_r(date_parse("2016-09-25 10:45:30.5")); //Array ( [year] => 2016 [month] => 9 [day] => 25 [hour] => 10 [minute] => 45 [second] => 30 [fraction] => 0.5 [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => ) //======================================== //从 2016 年 9 月 29 日减去 4 天 //date_sub() //函数从指定日期减去日、月、年、时、分和秒。 $date = date_create("2016-09-29"); date_sub($date,date_interval_create_from_date_string("4 days")); echo date_format($date,"y-m-d"); //16-09-25 //======================================== //返回有关 2016 年 1 月 1 日,纬度 31.2283,经度 121.4755 的日出/日落和黄昏开始/黄昏结束的信息 $sun_info = date_sun_info(strtotime("2016-01-01"),31.2283,121.4755); foreach($sun_info as $key=>$val){ echo "$key:".date("H:i:s",$val)."
"
; } // sunrise:06:52:34 // sunset:17:01:56 // transit:11:57:15 // civil_twilight_begin:06:26:00 // civil_twilight_end:17:28:30 // nautical_twilight_begin:05:55:49 // nautical_twilight_end:17:58:41 // astronomical_twilight_begin:05:26:16 // astronomical_twilight_end:18:28:14 //======================================== echo("上海,中国:日期".date("D M d y")); echo("
日出时间"
); echo(date_sunrise(time(),SUNFUNCS_RET_STRING,31.22,121.47,90,8)); // 上海,中国:日期Thu Oct 31 19 // 日出时间06:11 //======================================== //设置时间: $date = date_create("2016-09-25"); date_time_set($date,12,36); echo date_format($date,"Y-m-d H:i:s"); //2016-09-25 12:36:00 //======================================== //返回今天的日期和时间的 Unix 时间戳: $date = date_create(); echo date_timestamp_get($date); //1572488325 //======================================== //设置基于 Unix 时间戳的日期和时间 $date = date_create(); date_timestamp_set($date,1472988263); echo date_format($date,"U=y-m-d H:i:s"); //1472988263=16-09-04 19:24:23 //======================================== //date_timezone_get()返回给定 DateTime 对象的时区: $date = date_create(null,timezone_open("Europe/Paris")); $tz = date_timezone_get($date); echo timezone_name_get($tz); //Europe/Paris //======================================== //设置 DateTime 对象的时区 $date = date_create("2016-09-25",timezone_open("Asia/Shanghai")); echo date_format($date,"y-m-d H:i:s"); //16-09-25 00:00:00 //======================================== //格式化本地日期和时间,并返回已格式化的日期字符串: echo date("l")."
"
; echo date("l js \of F Y h:i:s A"); // Thursday // Thursday 3142 of October 2019 10:27:42 AM //======================================== //返回当前本地的日期/时间的日期/时间信息: print_r(getdate()); //Array ( [seconds] => 36 [minutes] => 29 [hours] => 10 [mday] => 31 [wday] => 4 [mon] => 10 [year] => 2019 [yday] => 303 [weekday] => Thursday [month] => October [0] => 1572488976 ) //======================================== //返回当前时间 print_r(gettimeofday()); echo "
"
; echo gettimeofday(true); // Array ( [sec] => 1572489098 [usec] => 739874 [minuteswest] => -480 [dsttime] => 0 ) // 1572489098.7399 //======================================== //格式化 GMT/UTC 日期和时间,并返回已格式化的日期字符串 echo gmdate("l"); echo "
"
; echo gmdate("l js \of F Y h:i:s A"); // Thursday // Thursday 3151 of October 2019 02:33:51 AM //======================================== //返回 GMT 日期的 UNIX 时间戳,然后使用它来查找该日期的天 echo "Oct 3, 1975 was on a ".date("l",gmmktime(0,0,0,10,3,1975)); //Oct 3, 1975 was on a Friday //======================================== //根据区域设置来格式化 GMT/UTC 日期和时间 echo(gmstrftime("%B %d %Y,%x%z",mktime(20,0,0,12,31,98))."
"
); echo "
"
; setlocale(LC_ALL,"hu_HU/UTF8"); //December 31 1998,12/31/98+0800 //======================================== // idate() 函数把本地时间/日期格式化为整数 // https://www.w3school.com.cn/php/func_date_idate.asp //======================================== //以数值数组和关联数组的形式输出本地时间 print_r(localtime()); echo "
"
; print_r(localtime(time(),true)); // Array ( [0] => 40 [1] => 41 [2] => 10 [3] => 31 [4] => 9 [5] => 119 [6] => 4 [7] => 303 [8] => 0 ) // Array ( [tm_sec] => 40 [tm_min] => 41 [tm_hour] => 10 [tm_mday] => 31 [tm_mon] => 9 [tm_year] => 119 [tm_wday] => 4 [tm_yday] => 303 [tm_isdst] => 0 ) //======================================== //返回当前 Unix 时间戳的微秒数 echo(microtime()); //0.23686400 1572489797 //======================================== //返回一个日期的 UNIX 时间戳。然后使用它来查找该日期的天 echo "Oct 3, 1975 was on a ".date("l",mktime(0,0,0,10,3,1975)); //Oct 3, 1975 was on a Friday //======================================== //根据区域设置来格式化本地日期和时间 echo(strftime("%B %d %y,%x %z",mktime(20,0,0,12,31,98))); setlocale(LC_ALL,"hu_HU.UTF8"); echo(strftime("%y.%B%d.%A.%x%z")); //December 31 98,12/31/98 +080019.October31.Thursday.10/31/19+0800 //======================================== //解析由 strftime() 生成的时间/日期 $format="%d/%m/%Y %H:%M:%S"; $strf=strftime($format); echo("$strf"); print_r(strptime($strf,$format)); //31/10/2019 10:53:31 //======================================== //输出亚洲的所有时区: //print_r(timezone_identifiers_list(16)); //Array ( [0] => Asia/Aden [1] => Asia/Almaty [2] => Asia/Amman [3] => Asia/Anadyr [4] => Asia/Aqtau [5] => Asia/Aqtobe [6] => Asia/Ashgabat [7] => Asia/Atyrau [8] => Asia/Baghdad [9] => Asia/Bahrain [10] => Asia/Baku [11] => Asia/Bangkok [12] => Asia/Barnaul [13] => Asia/Beirut [14] => Asia/Bishkek [15] => Asia/Brunei [16] => Asia/Chita [17] => Asia/Choibalsan [18] => Asia/Colombo [19] => Asia/Damascus [20] => Asia/Dhaka [21] => Asia/Dili [22] => Asia/Dubai [23] => Asia/Dushanbe [24] => Asia/Famagusta [25] => Asia/Gaza [26] => Asia/Hebron [27] => Asia/Ho_Chi_Minh [28] => Asia/Hong_Kong [29] => Asia/Hovd [30] => Asia/Irkutsk [31] => Asia/Jakarta [32] => Asia/Jayapura [33] => Asia/Jerusalem [34] => Asia/Kabul [35] => Asia/Kamchatka [36] => Asia/Karachi [37] => Asia/Kathmandu [38] => Asia/Khandyga [39] => Asia/Kolkata [40] => Asia/Krasnoyarsk [41] => Asia/Kuala_Lumpur [42] => Asia/Kuching [43] => Asia/Kuwait [44] => Asia/Macau [45] => Asia/Magadan [46] => Asia/Makassar [47] => Asia/Manila [48] => Asia/Muscat [49] => Asia/Nicosia [50] => Asia/Novokuznetsk [51] => Asia/Novosibirsk [52] => Asia/Omsk [53] => Asia/Oral [54] => Asia/Phnom_Penh [55] => Asia/Pontianak [56] => Asia/Pyongyang [57] => Asia/Qatar [58] => Asia/Qostanay [59] => Asia/Qyzylorda [60] => Asia/Riyadh [61] => Asia/Sakhalin [62] => Asia/Samarkand [63] => Asia/Seoul [64] => Asia/Shanghai [65] => Asia/Singapore [66] => Asia/Srednekolymsk [67] => Asia/Taipei [68] => Asia/Tashkent [69] => Asia/Tbilisi [70] => Asia/Tehran [71] => Asia/Thimphu [72] => Asia/Tokyo [73] => Asia/Tomsk [74] => Asia/Ulaanbaatar [75] => Asia/Urumqi [76] => Asia/Ust-Nera [77] => Asia/Vientiane [78] => Asia/Vladivostok [79] => Asia/Yakutsk [80] => Asia/Yangon [81] => Asia/Yekaterinburg [82] => Asia/Yerevan ) //======================================== //返回指定时区的位置信息 $tz=timezone_open("America/New_York"); echo timezone_location_get($tz); //======================================== //返回时区的名称 $tz = timezone_open("America/New_York"); echo timezone_name_get($tz); //America/New_York //======================================== ?>

字符串的方法


//======================php字符串练习
//在A前面添加斜线
//addcslashes() 函数返回在指定字符前添加反斜杠的字符串。
$str = addcslashes("A001 A002 A003","A");
echo $str;
//\A001 \A002 \A003
//=======================
//在每个双引号(")前添加反斜杠:
//addslashes() 函数返回在预定义字符之前添加反斜杠的字符串。
$str = addslashes('shanghai is the "giggest" city in china.');
echo $str;
//========================
//bin2hex() 函数把 ASCII 字符的字符串转换为十六进制值。字符串可通过使用 pack() 函数再转换回去。
$str = bin2hex("Shanghai");
echo $str;
echo '
'
; echo pack($str);//Type 5: unknown format code 格式不对 //========================= //从字符串右端移除字符: $str = "hello world"; echo $str ."
"
; echo chop($str,"world"); //========================== //从不同的 ASCII 值返回字符 echo chr(61); // 十进制 echo '
'
; echo chr(061);// 八进制值 echo '
'
; echo chr(0x61);// 十六进制值 // ========================== //在每个字符后分割一次字符串,并在每个分割后添加 ".": $str = "shanghai"; echo chunk_split($str,1,".");//s.h.a.n.g.h.a.i. // ============================ //把字符串由一种字符集转换成另一种: $str = "hello world ! ???"; echo $str."
"
; echo convert_cyr_string($str,'w','a'); // ============================= //对 uuencode 编码的字符串进行解码: $str = "hihihi"; echo uuencode($str);//Call to undefined function uuencode() $str = ",2&5L;&\@=V]R;&0A"; echo convert_uudecode($str);//Hello world! //================================ //convert_uuencode() 函数使用 uuencode 算法对字符串进行编码。 $str = "hello world!"; echo convert_uuencode($str);//,:&5L;&\@=V]R;&0A ` //=============================== //返回一个字符串,包含所有在 "Hello World!" 中使用过的不同字符(模式 3): $str = "hello world"; echo count_chars($str,3);//dehlorw // 0 - 数组,ASCII 值为键名,出现的次数为键值 // 1 - 数组,ASCII 值为键名,出现的次数为键值,只列出出现次数大于 0 的值 // 2 - 数组,ASCII 值为键名,出现的次数为键值,只列出出现次数等于 0 的值 // 3 - 字符串,带有所有使用过的不同的字符 // 4 - 字符串,带有所有未使用过的不同的字符 //echo count_chars($str,4);//其他的不是报错就是乱码 //================================= //crc32() 函数计算字符串的 32 位 CRC(循环冗余校验)。 $str = crc32("shanghai"); printf("%u\n",$str);//2998110323 //================================ //把字符串打散为数组: $str = "hello world. i love shanghai!"; print_r(explode(' ',$str));//Array ( [0] => hello [1] => world. [2] => i [3] => love [4] => shanghai! ) //================================ //fprintf() 函数把格式化的字符串写入指定的输出流(例如:文件或数据库)。写进了test.txt文本 $number = 9; $str ="beijing"; $file = fopen("test.txt","w"); echo fprintf($file,"There are %u million bicycles in %s .",$number,$str);//41 //================================= //输出 htmlspecialchars 函数使用的翻译表: print_r(get_html_translation_table()); Array ( ["] => " [&] => & [<] => < [>] => > ) //============================== //反向显示希伯来字符: echo hebrev("? ???? ?????");//????? ???? ? //hebrev() 函数把希伯来文本从右至左的流转换为左至右的流。 //============================= //hebrevc() 函数把希伯来文本从右至左的流转换为左至右的流。同时,把新行(\n)转换为
echo hebrevc("? ?? ???\n? ??? ????"); //??? ?? ? //???? ??? ? //============================= //把十六进制值转换为 ASCII 字符: echo hex2bin("4856c6c6f20576f726c642"); //输出乱码 //============================ //把 HTML 实体转换为字符: $str = "<© W3Sçh°°¦§>"; echo html_entity_decode($str); //输出的是这个<© W3Sçh°°¦§>不是html的结构代码 //=========================== /*把字符转换为 HTML 实体: $str = ""; echo htmlentities($str); */ //============================= //把预定义的 HTML 实体 "<"(小于)和 ">"(大于)转换为字符: $str = "this is some bold text."; echo htmlspecialchars_decode($str); //this is some bold text. //============================= $arr = array('hello','world','i','love','shanghai!'); echo implode(" ",$arr); //hello world i love shanghai! //============================ //把数组元素组合为一个字符串: $arr = array('hello','world!','i','love!'); echo join(' ',$arr); //hello world! i love! //============================= //把 "Hello" 的首字符转换为小写: echo lcfirst("Hello world!"); //hello world! //============================= //计算两个字符串之间的 Levenshtein 距离: echo levenshtein("Hello World","ello World"); echo "
"
; echo levenshtein("Hello World","ello World",10,20,30); // 1 // 30 //============================== //查找美国本地的数字格式化信息: setlocale(LC_ALL,"US"); $locale_info = localeconv(); print_r($locale_info); //Array ( [decimal_point] => . [thousands_sep] => , [int_curr_symbol] => USD [currency_symbol] => $ [mon_decimal_point] => . [mon_thousands_sep] => , [positive_sign] => [negative_sign] => - [int_frac_digits] => 2 [frac_digits] => 2 [p_cs_precedes] => 1 [p_sep_by_space] => 0 [n_cs_precedes] => 1 [n_sep_by_space] => 0 [p_sign_posn] => 3 [n_sign_posn] => 0 [grouping] => Array ( [0] => 3 ) [mon_grouping] => Array ( [0] => 3 ) ) //========================== //从字符串左侧移除字符 $str = "Hello World!"; echo $str."
"
; echo ltrim($str,"Hello");//区分大小写 // Hello World! // World! //========================== $str = "123456"; echo md5($str);//e10adc3949ba59abbe56e057f20f883e //========================== //计算文本文件 "test.txt" 的 MD5 散列: $filename = "test.txt"; $md5file = md5_file($filename); echo $md5file; //6e51f10405a0143c6fc7b5c27ec98cfa //============================ //计算 "World" 的 metaphone 键: echo metaphone("Computer"); //KMPTR //============================ //en_US 国际格式: $number = 1234.56; setlocale(LC_MONETARY,"en_US"); echo money_format("The price is %i", $number); //Call to undefined function money_format() in //============================ //在字符串中的新行(\n)之前插入换行符: echo nl2br("One line.\nAnother line."); // One line. // Another line. //============================ //格式化数字: echo number_format("5000000")."
"
; echo number_format("5000000",2)."
"
; echo number_format("5000000",2,",","."); // 5,000,000 // 5,000,000.00 // 5.000.000,00 //=========================== //返回 "S" 的 ASCII值 echo ord("S")."
"
; echo ord("shangahi")."
"
;//区分大小写 //83 //115 //========================== //把查询字符串解析到变量中: parse_str("name=Bill&age=60"); echo $name."
"
; echo $age; // Bill // 60 //========================= //输出格式化的字符串: $number = 9; $str = "北京"; printf("在%s有%u百万辆自行车。",$str,$number); // 在北京有9百万辆自行车。 //========================== //把 quoted-printable 字符串解码为 8 位 ASCII 字符串: $str = "I=0Alove=)AShanghai"; echo quoted_printable_decode($str); //I love=)AShanghai //========================== //在预定义字符前添加反斜杠: $str = "Hello World.(can you hear me?)"; echo quotemeta($str); //Hello World\.\(can you hear me\?\) //========================= //从字符串右侧移除字符: $str = "Hello World!"; echo $str."
"
; echo rtrim($str,"World!"); // Hello World! // Hello //========================= //设置地区为 US English,然后重新设置回系统默认: echo setlocale(LC_ALL,"US"); echo "
"
; echo setlocale(LC_ALL,null); //English_United States.1252 //Chinese (Simplified)_People's Republic of China.936 //========================= //计算字符串 "Hello" 的 SHA-1 散列: $str = "shanghai"; echo sha1($str); //d43ad24e210029fbce3c25663b75f28a6c076167 //=========================== //计算文本文件 "test.txt" 的 SHA-1 散列: $filename = "test.txt"; $sha1file = sha1_file($filename); echo $sha1file; //3c544300960b0667eec8959ebc6ad922e24dc8e8 //=========================== //计算两个字符串的相似度,并返回匹配字符的数目: echo similar_text("Hello World","Hello Shanghai"); //6 //========================== //计算 "Hello" 的 soundex 键: $str = "Shanghai"; echo soundex($str); //S520 //========================= //把百分号(%)符号替换成一个作为参数进行传递的变量: $number = 2; $str = "Shanghai"; $txt = sprintf("There are %u million cars in %s.",$number,$str); echo $txt; //There are 2 million cars in Shanghai. //========================= //解析字符串: $str = "age:30 weight:60kg"; sscanf($str,"age:%d weight:%dkg",$age,$weight); var_dump($age,$weight); //int(30) int(60) //========================== //把字符串 "Hello world!" 中的字符 "WORLD"(不区分大小写)替换成 "Shanghai": echo str_ireplace("WORLD","Shanghai","Hello world!"); //Hello Shanghai! //========================= //填充字符串的右侧,到 30 个字符的新长度: $str ="Hello World"; echo str_pad($str,30,"."); //Hello World................... //========================= //把字符串 "Shanghai " 重复 5 次: echo str_repeat("shanghai",5); //shanghaishanghaishanghaishanghaishanghai //========================== //把字符串 "Hello world!" 中的字符 "world" 替换为 "Shanghai": echo str_replace("world","shanghai","hello world"); //hello shanghai //=========================== //编码然后解码字符串: echo str_rot13("i love shanghai"); echo "
"
; echo str_rot13("v ybir funatunv"); // v ybir funatunv // i love shanghai //=========================== //随机地打乱字符串中的所有字符: echo str_shuffle("i love shanghai"); //oiaais vhhlne g(每一次都不一样) //=========================== //把字符串 "Shanghai" 分割到数组中: print_r(str_split("Shanghai")); //Array ( [0] => S [1] => h [2] => a [3] => n [4] => g [5] => h [6] => a [7] => i ) //============================ //计算字符串 "I love Shanghai!" 中的单词数: echo str_word_count("i love shangahi"); //3 //============================ //比较两个字符串(不区分大小写): echo strcasecmp("shanghai","SHANGHAI"); //-0 //============================ //查找 "world" 在 "Hello world!" 中的第一次出现,并返回此字符串的其余部分: echo strchr("Hello world!","world"); //world! echo strchr("Hello world!","Hello"); //Hello world! //============================ //比较两个字符串(区分大小写): echo strcmp("Hello world!","Hello world!"); //0 //============================= //比较字符串: setlocale(LC_COLLATE,'NL'); echo strcoll("Hello World!","Hello World!"); echo "
"
; setlocale(LC_COLLATE,'en_US'); echo strcoll("Hello World","Hello World"); //0 //0 //======================== //输出在字符串 "Hello world!" 中找到字符 "w" 之前查找的字符数:字符串里面区分大小写 echo strcspn("Hello world!","w"); //6 //======================== //剥去字符串中的 HTML 标签: echo strip_tags("Hello world!"); //Hello world! //+======================== //删除 "World!" 前面的反斜杠: echo stripslashes("Hello \World!"); //Hello World! //========================= //删除反斜杠 echo stripslashes("Who\`s Bill Gates?"); //Who`s Bill Gates? //========================== //查找 "php" 在字符串中第一次出现的位置:(字符串中不区分大小写) echo stripos("You love php,i love php too!","PHP"); //9 //========================== //查找 "world" 在 "Hello world!" 中的第一次出现,并返回字符串的剩余部分: echo stristr("Hello world!","WORLD"); //world! //=========================== //函数返回字符串 "Shanghai" 的长度: echo strlen("456852123"); //9 //=========================== //使用"自然"算法来比较两个字符串(不区分大小写) echo strnatcasecmp("2hello world","10hello world"); echo '
'
; echo strnatcasecmp("10hello world","2hello world"); // -1 // 1 //在自然算法中,数字 2 小于数字 10。在计算机排序中,10 小于 2,这是因为 10 中的第一个数字小于 2。 //=========================== //使用"自然"算法来比较两个字符串(区分大小写) echo strnatcmp("2hello world","10hello world"); echo '
'
; echo strnatcmp("10hello world","2hello world"); // -1 // 1 //=========================== //比较两个字符串(不区分大小写) echo strncasecmp("i love china","i love Shanghai!",6); //0 // string1 必需。规定要比较的第一个字符串。 // string2 必需。规定要比较的第二个字符串。 // length 必需。规定每个字符串用于比较的字符数。 //========================== //比较两个字符串(区分大小写): echo strncmp("i love China","I love Shang!",6); //1 //========================== //在字符串中搜索字符 "Sh",并返回字符串中从指定字符第一次出现的位置开始的剩余部分: echo strpbrk("I love Shanghai!","Sh"); //Shanghai! //=========================== //查找 "php" 在字符串中第一次出现的位置: echo strpos("you love php,but this php is not nice!","php"); //9 //=========================== //搜索 "Shanghai" 在字符串中的位置,并返回从该位置到字符串结尾的所有字符: echo strrchr("i like shangahi!","shanghai"); //shangahi! //=========================== //反转字符串 "I love Shanghai!": echo strrev("i love shanghai"); //iahgnahs evol i //=========================== //查找 "php" 在字符串中最后一次出现的位置: echo strripos("you love php,i love php too!","php"); //20 //=========================== //查找 "php" 在字符串中最后一次出现的位置: echo strrpos("you love php,i love php too!","php"); //20 //=========================== //返回在字符串 "Hello world!" 中包含字符 "kHlleo" 的数目: echo strspn("Hello world!","kHlleo"); //5 //=========================== //查找 "Shanghai" 在 "I love Shanghai!" 中的第一次出现,并返回字符串的剩余部分: echo strstr("i love shanghai !","shanghai"); //shanghai ! //=========================== //把所有字符转换为小写: echo strtolower("Hello WORLD!"); //hello world! //=========================== //把所有字符转换为大写: echo strtoupper("Hello WORLD!"); //HELLO WORLD! //=========================== //把字符串中的字符 "ia" 替换为 "eo": echo strtr("Hilla Warld","ia","eo"); //Hello World //=========================== //从字符串中返回 "world": echo substr("Hello World",6); //World //=========================== //比较两个字符串: echo substr_compare("Hello World","Hello World",0); //0 //=========================== //计算 "Shanghai" 在字符串中出现的次数: echo substr_count("I love Shanghai. Shanghai is the biggest city in china.","Shanghai"); //2 //=========================== //把 "Hello" 替换成 "world": echo substr_replace("Hello","World",0); //World //=========================== //移除字符串两侧的字符("Hello" 中的 "He" 以及 "World" 中的 "d!"): $str = "Hello world!"; echo $str."
"
; echo trim($str,"Hed"); // Hello world! // llo world! //=========================== //把 "hello" 的首字符转换为大写: echo ucfirst("hello world!"); //Hello world! //=========================== //把每个单词的首字符转换为大写: echo ucwords("hello world"); //Hello World //=========================== //把文本写入名为 "test.txt" 的文本文件 $number = 9; $str = "Beijing"; $file = fopen("test.txt","w"); echo vfprintf($file,"there are %u million bicycles in %s.",array($number,$str)); //40 //=========================== //输出格式化的字符串: $number = 9; $str = "beijing"; vprintf("There are %u million bicycles in %s.",array($number,$str)); //There are 9 million bicycles in beijing. //=========================== //把格式化字符串写入变量中: $number = 9; $str = "beijing"; $txt = vsprintf("there are %u million bicycles in %s.",array($number,$str)); echo $txt; //there are 9 million bicycles in beijing. //=========================== //按照指定长度对字符串进行折行处理: $str = "长单词的一个例子:Supercalifragulistic"; echo wordwrap($str,15,"
\n"
); //长单词的一个例子:Supercalifragulistic //判断这个字符转里面有这个字符串 substr_count substr_compare strripos ?>

数组的方法


//将数组的所有的键转换为大写字母:
$age = array("Bill"=>"60","Steve"=>"56","Mark"=>"31");
print_r(array_change_key_case($age,CASE_UPPER));
//Array ( [BILL] => 60 [STEVE] => 56 [MARK] => 31 )
//==============================
//把数组分割为带有两个元素的数组:
$car = array("haila","tuoer","meidui","pider");
print_r(array_chunk($car,2));
//Array ( [0] => Array ( [0] => haila [1] => tuoer ) [1] => Array ( [0] => meidui [1] => pider ) )
//==============================
//通过合并两个数组来创建一个新数组,其中的一个数组元素为键名,另一个数组元素为键值:
$fname = array("Bill","Steve","Mark");
$age = array("60","56","31");
$c = array_combine($fname,$age);
print_r($c);
//Array ( [Bill] => 60 [Steve] => 56 [Mark] => 31 )
//==============================
//对数组中的所有值进行计数:
$a = array("A","Cat","Dog","A","Dog");
print_r(array_count_values($a));
//Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )
//==============================
//比较两个数组的键值,并返回差集:
$a1 = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2 = array("e"=>"red","f"=>"green","g"=>"blue");
$result = array_diff($a1,$a2);
print_r($result);
//Array ( [d] => yellow )
//==============================
//比较两个数组的键和值,并返回差集:
$a1 = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2 = array("e"=>"red","f"=>"green","g"=>"blue");
$result = array_diff_assoc($a1,$a2);
print_r($result);
//Array ( [a] => red [b] => green [c] => blue [d] => yellow )
//==============================
//比较两个数组的键名,并返回差集:
$a1 = array("a"=>"red","b"=>"green","c"=>"blue");
$a2 = array("a"=>"red","c"=>"blue","d"=>"pink");
$result = array_diff_key($a1,$a2);
print_r($result);
//Array ( [b] => green )
//==============================
//用值填充数组:
$a1 = array_fill(3,4,"blue");
print_r($a1);
//Array ( [3] => blue [4] => blue [5] => blue [6] => blue )
//==============================
//使用指定的键和值填充数组:
$key = array("a","b","c","d");
$a1 = array_fill_keys($key,"BLUE");
print_r($a1);
//Array ( [a] => BLUE [b] => BLUE [c] => BLUE [d] => BLUE )
//==============================
//反转数组中所有的键以及它们关联的值
$a1 = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$result = array_flip($a1);
print_r($result);
//Array ( [red] => a [green] => b [blue] => c [yellow] => d )
//==============================
//比较两个数组的键值,并返回交集:
$a1 = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2 = array("e"=>"red","f"=>"green","g"=>"blue");
$result = array_intersect($a1,$a2);
print_r($result);
//Array ( [a] => red [b] => green [c] => blue )
//==============================
//比较两个数组的键名和键值,并返回交集:
$a1 = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2 = array("a"=>"red","b"=>"green","c"=>"blue");
$result = array_intersect_assoc($a1,$a2);
print_r($result);
//Array ( [a] => red [b] => green [c] => blue )
//==============================
//比较两个数组的键名,并返回交集:
$a1 = array("a"=>"red","b"=>"222","c"=>"333");
$a2 = array("a"=>"red","c"=>"333","d"=>"666");
$result = array_intersect_key($a1,$a2);
print_r($result);
//Array ( [a] => red [c] => 333 )
//==============================
//检查键名 "Volvo" 是否存在于数组中:
array_key_exists("Volvo",$a)
//==============================
//返回包含数组中所有键名的一个新数组
$a1 = array("a"=>"海拉","b"=>"雷神托尔","c"=>"美国队长","d"=>"钢铁侠");
print_r(array_keys($a1));
//Array ( [0] => a [1] => b [2] => c [3] => d )
//==============================
//把两个数组合并为一个数组:
$a1 = array("red","green");
$a2 = array("blue","yellow");
print_r(array_merge($a1,$a2));
//Array ( [0] => red [1] => green [2] => blue [3] => yellow )
//==============================
/*把两个数组合并为一个数组:
array_merge_recursive() 函数把一个或多个数组合并为一个数组。

该函数与 array_merge() 函数的区别在于处理两个或更多个数组元素有相同的键名时。array_merge_recursive() 不会进行键名覆盖,而是将多个相同键名的值递归组成一个数组。
*/
$a1 = array("a"=>"123","b"=>"234");
$a2 = array("c"=>"345","d" =>"456");
print_r(array_merge_recursive($a1,$a2));
//Array ( [a] => 123 [b] => 234 [c] => 345 [d] => 456 )
//==============================
//返回一个升序排列的数组:
$a = array("dog","cat","peek","horse","bear","panana");
array_multisort($a);
print_r($a);
//Array ( [0] => bear [1] => cat [2] => dog [3] => horse [4] => panana [5] => peek )
//==============================
//返回 5 个元素,并将 "blue" 值插入数组的新元素中:
$a = array("red","green");
print_r(array_pad($a,5,"blue"));
//Array ( [0] => red [1] => green [2] => blue [3] => blue [4] => blue )
//==============================
//删除数组中的最后一个元素
$a = array("red","blue","green");
array_pop($a);
print_r($a);
//Array ( [0] => red [1] => blue )
//==============================
//计算并返回数组的乘积:
$a = array(5,5);
echo(array_product($a));
//25
//==============================
//向数组尾部插入 "blue" 和 "yellow":
$a = array("red","green");
array_push($a,"blue","yellow");
print_r($a);
//Array ( [0] => red [1] => green [2] => blue [3] => yellow )
//==============================
//返回包含随机键名的数组:
$a = array("111","222","333","444","555");
$random_keys = array_rand($a,3);
echo $a[$random_keys[0]]."
"
; echo $a[$random_keys[1]]."
"
; echo $a[$random_keys[2]]."
"
; //111 //333 //555 //============================== //使用第二个数组($a2)的值替换第一个数组($a1)的值: $a1 = array("red","green"); $a2 = array("blue","yellow"); print_r(array_replace($a1,$a2)); //Array ( [0] => blue [1] => yellow ) //============================== //递归地使用第二个数组($a2)的值替换第一个数组($a1)的值: $a1 = array("a"=>array("red"),"b"=>array("green","blue"),); $a2 = array("a"=>array("yellow"),"b"=>array("black")); print_r(array_replace_recursive($a1,$a2)); //Array ( [a] => Array ( [0] => yellow ) [b] => Array ( [0] => black [1] => blue ) ) //============================== //以相反的元素顺序返回数组: $a = array("a"=>"111","b"=>"222","c"=>"333","d"=>"444"); print_r(array_reverse($a)); //Array ( [d] => 444 [c] => 333 [b] => 222 [a] => 111 ) //============================== //在数组中搜索键值 "111",并返回它的键名: $a = array("a"=>"111","b"=>"222","c"=>"333"); echo array_search("111",$a); //a //============================== //删除数组中的第一个元素(111),并返回被删除元素的值 $a = array("a"=>"111","b"=>"222","c"=>"333"); echo array_shift($a); print_r($a); //111Array ( [b] => 222 [c] => 333 ) //============================== //从数组的第三个元素开始取出,并返回数组中的其余元素: $a = array("111","222","333","444","555","666"); print_r(array_slice($a,2)); //Array ( [0] => 333 [1] => 444 [2] => 555 [3] => 666 ) //============================== //从数组中移除元素,并用新元素取代它: $a1 = array("a"=>"111","b"=>"222","c"=>"333","d"=>"444"); $a2 = array("a"=>"133","b"=>"242"); array_splice($a1,0,2,$a2); print_r($a1); //Array ( [0] => 133 [1] => 242 [c] => 333 [d] => 444 ) //============================== //返回数组中所有值的和(5+15+25): $a = array(5,15,25); echo array_sum($a); //45 //============================== //移除数组中重复的值: $a = array("a"=>"111","b"=>"222","c"=>"111"); print_r(array_unique($a)); //Array ( [a] => 111 [b] => 222 ) //============================== //把元素 "blue" 插入数组中: $a =array("a"=>"red","b"=>"green"); array_unshift($a,"blue"); print_r($a); //Array ( [0] => blue [a] => red [b] => green ) //============================== //返回数组的所有值(非键名): $a = array("name"=>"Bill","age"=>"60","country"=>"usa"); print_r(array_values($a)); //Array ( [0] => Bill [1] => 60 [2] => usa ) //============================== //按照键值对关联数组进行降序排序: $age = array("Bill"=>"60","Steve"=>"56","mark"=>"31"); arsort($age); print_r($age); //Array ( [Bill] => 60 [Steve] => 56 [mark] => 31 ) //============================== //按照键值对关联数组进行升序排序: $age = array("Bill"=>"60","Steve"=>"56","mark"=>"31"); asort($age); print_r($age); //Array ( [mark] => 31 [Steve] => 56 [Bill] => 60 ) //============================== //创建一个包含变量名和它们的值的数组: $firstname = "bill"; $lastname = "Gates"; $age = "60"; $result = compact("firstname","lastname","age"); print_r($result); //Array ( [firstname] => bill [lastname] => Gates [age] => 60 ) //============================== //返回数组中元素的数目: $cars =array("Volvo","BMW","Toyota"); echo count($cars); //3 //============================== //输出数组中的当前元素的值: $people = array("bill","Steve","Mark","David"); echo current($people)."
"
; //bill //============================== //返回当前元素的键名和键值,并将内部指针向前移动: $people = array("bill","Steve","Mark","David"); print_r(each($people)); //Array ( [1] => bill [value] => bill [0] => 0 [key] => 0 ) //============================== //输出数组中的当前元素和最后一个元素的值: $people = array("bill","Steve","Mark","David"); echo current($people)."
"
; echo end($people); // bill // David //============================== //将键值 "Cat"、"Dog" 和 "Horse" 赋值给变量 $a、$b 和 $c $a = "original"; $my_array =array("a"=>"cat","b"=>"Dog","c"=>"horse"); extract($my_array); echo "\$a =$a; \$b=$b;\$c=$c"; //$a =cat; $b=Dog;$c=horse //============================== //in_array(); //============================== //从当前内部指针位置返回元素键名: $people = array("Bill","Steve","Mark","dawei","haila"); echo "键的当前位置:".key($people); //键的当前位置:0 //============================== //按照键名对关联数组进行降序排序: $age = array("Bill"=>"60","haila"=>"20","tuoer"=>"19","luoji"=>"18",); krsort($age); print_r($age); //Array ( [tuoer] => 19 [luoji] => 18 [haila] => 20 [Bill] => 60 ) //============================== //按照键名对关联数组进行升序排序: $age = array("Bill"=>"60","haila"=>"20","tuoer"=>"19","luoji"=>"18"); ksort($age); print_r($age); //Array ( [Bill] => 60 [haila] => 20 [luoji] => 18 [tuoer] => 19 ) //============================== //把数组中的值赋给一些变量: $my_array = array("dog","cat","horse"); list($a,$b,$c) = $my_array; echo "I have several animals, a $a, a $b and a $c."; //I have several animals, a dog, a cat and a horse. //============================== //natsort() //============================== //输出数组中的当前元素和下一个元素的值: $people = array("BIll","Steve","Mark","David"); echo current($people)."
"
; echo next($people); // BIll // Steve //============================== //输出数组中的当前元素的值: $people = array("Bill","Steve","Mark","David"); echo pos($people)."
"
; //Bill //============================== //输出数组中的当前元素、下一个元素和上一个元素的值: $people = array("Bill","Steve","Mark","David"); echo current($people)."
"
; echo next($people)."
"
; echo prev($people); // Bill // Steve // Bill //============================== //创建一个包含从 "0" 到 "5" 之间的元素范围的数组: $number = range(0,5); print_r($number); //Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 ) //============================== //输出数组中的当前元素和下一个元素的值,然后把数组的内部指针重置到数组中的第一个元素 $people = array("Bill","Steve","Mark","David"); echo current($people)."
"
; echo next($people)."
"
; echo reset($people)."
"
; // Bill // Steve // Bill //============================== //对数组 $cars 中的元素按字母进行降序排序: $cars = array("meisaidesi","xuefulai","jeep"); rsort($cars); print_r($cars); //Array ( [0] => xuefulai [1] => meisaidesi [2] => jeep ) //============================== //把数组中的元素按随机顺序重新排序: $my_array = array("red","green","blue","yellow","purple"); shuffle($my_array); print_r($my_array); //Array ( [0] => red [1] => blue [2] => yellow [3] => purple [4] => green ) //============================== //返回数组中元素的数目: $cars = array("benchi","baoma","wulinghongguang"); echo sizeof($cars); //3 //============================== //对数组 $cars 中的元素按字母进行升序排序: $cars = array("benchi","baoma","wulinghongguang"); sort($cars); print_r($cars); //Array ( [0] => baoma [1] => benchi [2] => wulinghongguang ) //============================== //使用用户自定义的比较函数对数组 $arr 中的元素按键值进行排序: function my_sort($a,$b){ if($a==$b){ return 0; } return ($a<$b)?-1:1; } $arr = array("a"=>4,"b"=>2,"c"=>8,"d"=>6); uasort($arr,"my_sort"); foreach($arr as $x=>$x_value){ echo "Key=".$x.",Value = ".$x_value; echo "
"
; } // Key=b,Value = 2 // Key=a,Value = 4 // Key=d,Value = 6 // Key=c,Value = 8 //============================== //使用用户自定义的比较函数对数组 $arr 中的元素按键名进行排序: //uksort() function my_sort($a,$b) { if ($a==$b) return 0; return ($a<$b)?-1:1; } // $arr=array("a"=>4,"b"=>2,"c"=>8,d=>"6"); // uksort($arr,"my_sort"); //============================== //使用用户自定义的比较函数对数组 $a 中的元素进行排序: // usort() function my_sort($a,$b) { if ($a==$b) return 0; return ($a<$b)?-1:1; } $a=array(4,2,8,6); usort($a,"my_sort"); ?>

超级变量

$GLOBALS  储存全局作用域中的变量
$_SERVER  获取服务器相关信息
$_REQUEST  获取POSTGET请求的参数
$_POST  获取表单的POST请求参数
$_GET  获取表单的GET请求参数
$_FILES  获取上传文件的的变量
$_ENV  获取服务器端环境变量的数组
$_COOKIE  浏览器cookie的操作
设置cookie:setcookie(name, value, expire, path, domain);
获取cookie:$_COOKIE["user"];
删除cookie:setcookie("user", "", time()-3600);//设置过期时间
$_SESSION  服务端session的操作
使用session前一定要session_start()启动session
储存session:$_SESSION["name"]="King";//数组操作
销毁session:unset($_SESSION["name"]);//销毁一个
session_destroy()unset($_SESSION);//销毁所有的session

魔术变量

__LINE__  文件中的当前行号。
__FILE__  文件的完整路径和文件名。如果用在被包含文件中,则返回被包含的文件名。
__DIR__  文件所在的目录。如果用在被包括文件中,则返回被包括的文件所在的目录。
__FUNCTION__  常量返回该函数被定义时的名字
__CLASS__  常量返回该类被定义时的名字(区分大小写)。
__METHOD__  类的方法名(PHP 5.0.0 新加)。返回该方法被定义时的名字(区分大小写)。
__NAMESPACE__  当前命名空间的名称(区分大小写)。此常量是在编译时定义的(PHP 5.3.0 新增)。
php7的特性(参照上一篇文章)

魔术方法

__construct():构造方法,往往进行与首次调用。
__destruct():析构方法,销毁对象时调用。
__get():获取一个类中成员属性时调用。
__set():设置一个类中成员属性时调用。
__isset():检测变量是否被设置时调用。
__unset():对不可访问属性时调用。
__cal():在对象中不可访问方法时调用。
__clone():复制对象时调用。
__tosring():当类变成字符串时调用。
__debuginfo():打印所调试信息时调用。

redis使用背景+所有的方法(参照redis穿透那篇文章)
js原生的方法
jq常用的方法(和区别)
1.取下拉菜单选中项的文本

$("#select option[selected]").text();//select和option之间有空格,option为select的子元素
$("#select option:selected").text();//如果写成$("#select").text();会把所有下拉菜单的文本选择出来

2.获取和设置下拉菜单的值

$("#select").val();//取值
$("#select").val("value");//设置,如果select中有值为value的选项,该选项就会被选中,如果不存在,则select不做任何变动

3.清空下拉菜单

$("#select").empty();
$("#select").html("");

4.给下列菜单添加元素

$('').appendto($("#select"));
$("#select").append('');

5.取单选框值

$("#id[checked]").val();

6.单选或复选按钮的选择

$("#id[value=val]").attr("checked",true);//选择
$("#id[value=val]").attr("checked","");//取消选择
$("#id[value=val]").attr("checked",false);//取消选择
$("#id[value=val]").removeattr("checked");//取消选择

7.取复选框值

$("input[type=checkbox][checked]").each(function(){
alert($(this).val());
})
//如果用$("input[type=checkbox][checked]").val(),只会返回第一个被选中的值

8.判断单选或复选框是否被选中

if($("#id").attr("checked")){}//判断选中
if($("#id").attr("checked")==true){}//判断选中
if($("#id").attr("checked")==undefined){}//判断未选中

9.元素可用不可用

$("#id").attr("disabled",false);//设为可用
$("#id").attr("disabled",true);//设为不可用

10.判断元素可用不可用

if($("#id").attr("disabled")){}//判断不可用
if($("#id").attr("disabled")==undefined){}//判断可用

文本框操作

取 值:var textval = $("#text_id").attr("value");
var textval = $("#text_id").val();
清除内容:$(”#txt”).attr(”value”,);
填充内容:$(”#txt”).attr(”value”,'123);

文本域操作

取 值:var textval = $("#text_id").attr("value");
var textval = $("#text_id").val();
清除内容:$(”#txt”).attr(”value”,);
填充内容:$(”#txt”).attr(”value”,'123);

单选按钮操作

取 值:var valradio = $("input[@type=radio][@checked]").val(); //只有一组Radio情况下
var valradio =$('input[@name=chart][@checked]').val(); //多组Radio情况下,根据name取一组的值

下拉框操作

取 值:var selectval = $('#sell').val();
设置选中:$("#select_id").attr("value",'test');//设置value=test的项目为当前选中项
添加新项:$("").appendTo("#select_id")//添加下拉框的option
清空下拉框:$("#select_id").empty()//清空下拉框

多选框操作

值:$("#chk_id").attr("checked",'');//未选中的值
$("#chk_id").attr("checked",true);//选中的值
if($("#chk_id").attr('checked')==undefined) //判断是否已经选中
$('input:radio[name="list"]:checked').val();

转载于:https://www.cnblogs.com/linji/archive/2011/04/07/2008030.html

//两种方法设置disabled属性
$('#areaSelect').attr("disabled",true);
$('#areaSelect').attr("disabled","disabled");
//三种方法移除disabled属性
$('#areaSelect').attr("disabled",false);
$('#areaSelect').removeAttr("disabled");
$('#areaSelect').attr("disabled","");
把你要输入的信息放到temp变量里面,通过这个,就可以输入到页面
$("#header").html(temp);
获取<li>里面的内容代码
$(“ul li”).eq(0).html();
获取<li>里面全部的东西
$(“ul li ”).each(function(){
Str.push($(this).html());
})
.html()用为读取和修改元素的HTML标签
.text()用来读取或修改元素的纯文本内容
.val()用来读取或修改表单元素的value值。
text() 方法方法设置或返回被选元素的文本内容
html() 方法返回或设置被选元素的内容 (inner HTML),包括标签。
如果该方法未设置参数,则返回被选元素的当前内容。
val() 方法返回或设置被选元素的值。
元素的值是通过 value 属性设置的。该方法大多用于 input 元素

https://www.cnblogs.com/WhiteM/p/7470105.html
如何阻止点击a标签刷新当前页面

href="#" 修改为 href=“javascript:void(0)” href=“javascript:void(0)

你可能感兴趣的:(php,js,数据库)