代码收藏

收集网站开发时常用到的代码(asp,php,js等)

JS读取写入Cookies操作

[CODE_LITE]function setCookie(name,value)
{
var Days = 30;
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
...

in_array - js模拟php中的in_array

in_array

in_array -- 检查数组中是否存在某个值
说明
bool in_array ( mixed needle, array haystack [, bool strict] )


在 haystack 中搜索 needle,如果找到则返回 TRUE,否则返回 FALSE。


[CODE_LITE]function in_array(needle, haystack) {
if(typeof needle == 'string' || typeof needle == 'number') {
...

iscn-判断是否有包括中文的字符串

/*
可用于用户名等不允许使用出现中文字符的地方
itlearner整理发布
*/
$str = "dd*(*d";
if (iscn($str)) {
echo "包括中文的字符串";
} else {
echo "不包括中文的字符串";
}

function iscn($str){
if (preg_match("/.*[".chr(0xa1)."-".chr(0xff)."]+.*/", $str)) {
return true;
} else {
return false;
...

JSON-PHP是一个自动完成JSON编码和解码的php开源代码工具

JSON一种轻量级的数据格式,由一位资深的软件工程师Douglas Crockford开发,全称为Javascript Object Notation。中文翻译为“JavaScript对象表示”,这个格式的数据可以很容易的被转换为javascript对象的格式,用于服务器端和客户端的数据传递,用于解决xml的过多冗余标签造成数据传输量过大的问题。

JSON-PHP是一个自动完成JSON编码和解码的php开源代码工具。

下载:json.rar
...

javascript计算小数保留两位小数,多位小数的方法

<SCRIPT LANGUAGE="JavaScript">
<!--
function formatFloat(src, pos)
{
    return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
}

alert(formatFloat("1212.2323", 2));
//-->
</SCRIPT>


还有如下几种方法:

[CODE_LITE]var test=88888.234;
...

getcon - 截取函数(itlearner原创)

/*
采集截取函数,主要用于分析采集的内容
Author: hx
getcon - 截取后去掉html字符,并去掉空格
getcon2 - 单纯截取,直接返回截取内容。
参数:
$par可接受两种格式:
1.前面字符{DATA}后面字符
2.正则表达式
*/

utf8_substr-用于utf8编码的字符串截取

/*
* 用于utf8编码的字符串截取
* itlearner注释
*/
function utf8_substr($str,$position,$length)

utf8_strlen - 获得UTF8编码的字符串的长度

[CODE_LITE]
/*
* 用于UTF8编码的程序
* 获得字符串的长度,一个中文表示3个长度
* itlearner编写
*/
function utf8_strlen($str) {
$count = 0;
for($i = 0; $i < strlen($str); $i++){
$value = ord($str[$i]);
if($value > 127) {
$count++;
if($value >= 192 && $value <= 223) $i++;
...

批量去掉链接获得焦点时的虚线框

传统办法:
在标签内加属性 代码多,修改难

<a href="link1.htm" onfocus="this.blur()">link1</a>

<a href="link1.htm" onfocus="this.close()">link1</a>

<a href="link1.htm" hidefocus="true">link1</a>

<a href="link1.htm" hidefocus="hidefocus">link1</a>

daddslashes -优化了的addslashes

Discuz用的一个基本函数。
[CODE_LITE]function daddslashes($string, $force = 0) {
if(!$GLOBALS['magic_quotes_gpc'] || $force) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = daddslashes($val, $force);
}
} else {
$string = addslashes($string);
...
分页:[«]1[2][3][4][»]

日历

<< 2008-4 >>

Sun

Mon

Tue

Wed

Thu

Fri

Sat

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

27

28

29

30

控制面板

网站分类

最新评论及回复

最近留言

最近引用

Search

站点统计

  • 文章总数:32
  • 评论总数:0
  • 引用总数:0
  • 浏览总数:300
  • 留言总数:0
  • 当前主题:itlearner
  • 当前样式:default

友情链接

图标汇集

  • RainbowSoft Studio Z-Blog
  • RainbowSoft Studio Z-Blog
  • 本站支持WAP访问
  • 订阅本站的 ATOM 1.0 新闻聚合
  • 订阅本站的 RSS 2.0 新闻聚合

Powered By Z-Blog 1.8 Devo Build 80201

Copyright 2008 ITlearner. Some Rights Reserved.