将指定的数组元素排在数组最后(0 位领导批示)

原题目地址: http://bbs.blueidea.com/thread-2953135-1-1.html

我的解法是删除那个数组元素再将array_push那个元素

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
function moveArrayElement(& $arr, $element)
{
    foreach($arr as $key => $value)
    {
        if($value == $element)
        {
            unset($arr[$key]);
        }
    }
    array_push($arr, $element);
}
$arr = array('楼主', '沙发', '板凳', '地板');
moveArrayElement($arr, '楼主');
print_r($arr);
?>

全文阅读 »

数组脏话查找关键字问题(4 位领导批示)

原问题地址: http://bbs.blueidea.com/thread-2948905-1-1.html


我想在数组含有“中国|||我国|||大地”,当有一句话同时出现“中国,我国,大地”时就提示有脏话,其他的如“ [2] => sex”就直接提示提示有脏话,这样数组怎样查找啊!大大们,出来帮我看看吧

我的解决方法. 思路是遍历数组进行逐个比较.

全文阅读 »

国庆60周年倒计时牌(4 位领导批示)

迎接祖国60周年华诞..抽空写了个倒计时牌(Javascript版本倒计时. 为奥运会写的)

DEMO: http://www.zdyi.com/flash/countdown.swf

全文阅读 »

Tags : ,

[备忘]Zend Studio for Eclipse 代码格式化(5 位领导批示)

使用方法:

打开 Window -> Preferences -> PHP -> Formatter 选择 Import 导入 xml 文件即可

全文阅读 »

仿京东商城图片展示效果(3 位领导批示)

QQ童鞋最近需要京东商城的图片展示效果..可怜的我被拉来当壮丁T_T.. 好久不写JS了.当作练手..

此效果要说也很简单.用到了JQuery的两个插件..
分别为:
内容滚动插件 jcarousel (Project地址: http://sorgalla.com/projects/jcarousel/)
图片放大镜插件 JQZoom (Project地址: http://www.mind-projects.it/projects/jqzoom/)

效果预览:
xxx

全文阅读 »

正则表达式子模式使用函数(1 位领导批示)

原问题地址: http://bbs.blueidea.com/thread-2944055-1-1.html

比较正确的解决方法:

1
2
3
4
5
<?php
$str="[thunder]ftp://3gset.cn:3gset@down.3gset.cn/谢谢你的温柔-S.H.E_飞轮海.mv.320x240.avi[/thunder]";
$str = preg_replace("/\[thunder\](.[^\[]*)\[\/thunder\]/ie","'<a href=\"thunder://'.base64_encode('\\1').'\">\\1</a>'", $str);
echo htmlspecialchars($str);
?>

这段代码的重点是使用了修饰符 e
正则表达式的修饰符 e 是这么解释的:
如果设置这个修饰符, preg_replace() 将在替换值里进行正常的涉及到 的替换, 等同于在 PHP 代码里面一样, 然后用于替换搜索到的字符串.

全文阅读 »

AS3学习之路(6) 简单动画(3 位领导批示)

通过定时器或enterFrame来实现对像的改变和时间联系起来以实现动画.

两个公式需要记忆一下:

(1) 计算弧度 radians = angle * Math.PI / 180
(2) 计算度数 angle = radians * 180 / Math.PI

全文阅读 »

个人常用软件(1 位领导批示)

暂列出本人常用软件. 我主要使用的操作系统有 WINDOWS 7, WINDOWS XP

一、RocketDock

一款模仿APPLE工具栏的软件. 一般重装系统后第一个安装的软件.能使我的桌面干干净净.没有多余图标.

相关网址: http://rocketdock.com/

二、Xlight

Xlight FTP服务器是非常容易使用的FTP服务器. 怎么使用就不用多说了. 自己试试吧.

相关网址: http://www.xlightftpd.com/cn/

全文阅读 »

Tags : ,

PHP创建文件重名.重新命名文件算法(0 位领导批示)

原问题: http://bbs.blueidea.com/thread-2942989-1-1.html

随便写了一个

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
31
32
33
34
35
36
37
38
<?php
function createFile($filename, $content = '')
{
    $fp = file_put_contents($filename, $content);
}
 
// 要创建的文件名称
$filename = 'www.txt';
 
if(file_exists($filename))
{
    // 打开当前目录
   $handle = opendir('./');
    $fileinfo = pathinfo($filename);
    //print_r($fileinfo);
    $files = array();
    while (false !== ($file = readdir($handle)))
    {
        if(preg_match_all("/{$fileinfo['filename']}(\d*)\.{$fileinfo['extension']}/i", $file, $match))
        {
            $max = max($match[1]);
            if($max)
            {
                $createfile = $fileinfo['filename'] . ($max + 1) . '.' . $fileinfo['extension'];
            }
            else
            {
                $createfile = $fileinfo['filename'] . '1.' . $fileinfo['extension'];
            }
        }
    }
    createFile($createfile);
}
else
{
    createFile($filename);
}
?>

另一种思路..使用临时文件作记数器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
function createFile($filename, $content = '')
{
    if(file_exists($filename . '.tmp'))
    {
        $num = (int) file_get_contents($filename . '.tmp') + 1;
        $fileinfo = pathinfo($filename);
        file_put_contents($fileinfo['filename'] . '(' . $num . ')' .$fileinfo['extension'], $content);
        file_put_contents($filename . '.tmp', $num);
    }
    else
    {
        file_put_contents($filename, $content);
        file_put_contents($filename . '.tmp', 1);
    }
}
createFile('test.txt');
?>

AS3学习之路(5) 拖动对象(0 位领导批示)

一个拖动对象的例子..重点学习的是: startDrag, stopDrag, dropTarget, setChildIndex 等方法的使用

?View Code ACTIONSCRIPT
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package
{
	import flash.display.Sprite;
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.filters.DropShadowFilter;
 
	public class ClassDrag extends Sprite
	{
		private var _red:Sprite;
		private var _blue:Sprite;
		private var _green:Sprite;
		private var _white:Sprite;
 
		// 被拖动对象原始坐标
		private var _startingLocation:Point;
 
		// 构造函数
		public function ClassDrag()
		{
			init();
		}
 
		// 初始化
		private function init():void
		{
			_red = new Sprite();
			createRectangle(_red, 0xff0000, 10, 10, 20, 20);
			_blue = new Sprite();
			createRectangle(_blue, 0x0000ff, 10, 35, 20, 20);
			_green = new Sprite();
			createRectangle(_green, 0x00cc00, 10, 60, 20, 20);
			_white = new Sprite();
			createRectangle(_white, 0xf0f0f0, 40, 10, 300, 300, false);
		}
 
		// 创建矩型
		private function createRectangle(rectangle:Sprite, color:uint, x:uint, y:uint, width:uint, height:uint, drag:Boolean = true):void
		{
			rectangle.graphics.beginFill(color);
			rectangle.graphics.drawRect(x, y, width, height);
			rectangle.graphics.endFill();
			addChild(rectangle);
 
			if(drag)
			{
				// 侦听事件
				rectangle.addEventListener(MouseEvent.MOUSE_DOWN, pickup);
				rectangle.addEventListener(MouseEvent.MOUSE_UP, place);
			}
		}
 
		// 拖动
		private function pickup(event:MouseEvent):void
		{
			// 保存原始坐标
			_startingLocation = new Point();
			_startingLocation.x = event.target.x;
			_startingLocation.y = event.target.y;
 
			// 开始拖动
			event.target.startDrag();
			// 加上阴影
			event.target.filters = [new DropShadowFilter()];
			// 拖动对象最前显示
			setChildIndex(DisplayObject(event.target), numChildren - 1);
		}
 
		// 拖动结束
		private function place(event:MouseEvent):void
		{
			// 拖动结束
			event.target.stopDrag();
			// 清除阴影
			event.target.filters = null;
 
			// 检测是否已经移动到目标区域
			if(event.target.dropTarget == _white)
			{
				var color:uint;
				switch(event.target)
				{
					case _red: color = 0xff0000; break;
					case _blue: color = 0x0000ff; break;
					case _green: color = 0x00cc00; break;
				}
 
				// 重新创建目标区域
				_white.graphics.clear();
				createRectangle(_white, color, 40, 10, 300, 300, false);
			}
 
			// 拖放对象回到原位
			event.target.x = _startingLocation.x;
			event.target.y = _startingLocation.y;
		}
	}
}
Tags : , ,

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志