对数组中任何元素操作函数

array_walk对数组中每一个值操作:

[cce_php]

<?php
$array = array( “a”,”b”,”c”,1,2,3);

function print_array($value){
echo “$value<br />”;
}
array_walk($array,’print_array’);
$myarray = array(“name”=>”zhangsan”,”number”=>”12″,”class”=>”one”);

function print_myarray($value,$key){
echo “$key=>$value<br />”;
}

//关联数组先为值,后为关键字
array_walk($myarray,’print_myarray’);
?>

[/cce_php]

 

PHP数组指针操作

each() 数组当前指针元素;

current() 数组第一个指针元素;

next() 数组下一个指针元素;

prev() 数组上一个指针元素;

reset() 返回指针到第一个元素;

end() 将指针移动数组结尾

 

PHP提取文本文件到数组

[cce_php]

<?php
//Create short variable name
$DOCUMENT_ROOT = $_SERVER[‘DOCUMENT_ROOT’];
?>
<html>
<head>
<title>
Bob’s Auto Parts – Customer Orders
</title>
</head>

<body>
<h1>Bob’s auto Parts</h1>
<h2>Customer Orders</h2>
<?php
//Read in the entire file.
//Each order becomes an element in the array

$orders= file(“$DOCUMENT_ROOT/../2015/orders.txt”);
//读取所有文件到$orders函数
$number_of_orders = count($orders);
//定义总行数
if ($number_of_orders == 0) {
echo “<p><strong>No orders pending. Please try again later.</strong></p>”;
}
echo “<table border=\”1\”>”;
echo “<tr><th bgcolor=\”#CCCCFF\”>Order Date</th>”;
echo “<th bgcolor=\”#CCCCFF\”>Tires</th>”;
echo “<th bgcolor=\”#CCCCFF\”>Oil</th>”;
echo “<th bgcolor=\”#CCCCFF\”>Spark</th>”;
echo “<th bgcolor=\”#CCCCFF\”>Total</th>”;
echo “<th bgcolor=\”#CCCCFF\”>Address</th></tr>”;

for ($i=0; $i<$number_of_orders; $i++) {
$line = explode(“\t”, $orders[$i]);

//将字符分割成以’\t’为分隔的小块

$line[1]= intval($line[1]);
$line[2]= intval($line[2]);
$line[3]= intval($line[3]);

//将字符转换为整数

echo “<tr>

<td>”.$line[0].”</td>
<td align=\”right\”>”.$line[1].”</td>
<td align=\”right\”>”.$line[2].”</td>
<td align=\”right\”>”.$line[3].”</td>
<td align=\”right\”>”.$line[4].”</td>
<td>”.$line[5].”</td>
</tr>”;
}

echo “</table>”;
?>

</body>
</html>

[/cce_php]

javascript弹窗代码

[cce_js]
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
  <Script language="javascript">
  
  window.onload = getMsg;
  window.onresize = resizeDiv;
  window.onerror = function(){}
  var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer,i = 0;
  function getMsg()
  {
  try{
  divTop = parseInt(document.getElementById("eMeng").style.top,10)
  divLeft = parseInt(document.getElementById("eMeng").style.left,10)
  divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10)
  divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10)
  docWidth = document.body.clientWidth;
  docHeight = document.body.clientHeight;
  document.getElementById("eMeng").style.top = parseInt(document.body.scrollTop,10) + docHeight + 10;// divHeight
  document.getElementById("eMeng").style.left = parseInt(document.body.scrollLeft,10) + docWidth - divWidth
  document.getElementById("eMeng").style.visibility="visible"
  objTimer = window.setInterval("moveDiv()",10)
  }
  catch(e){}
  }
  function resizeDiv()
  {
  i+=1
  if(i>3000) closeDiv()//控制时间
  try{
  divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10)
  divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10)
  docWidth = document.body.clientWidth;
  docHeight = document.body.clientHeight;
  document.getElementById("eMeng").style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10)
  document.getElementById("eMeng").style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10)
  }
  catch(e){}
  }
  function moveDiv()
  {
  try
  {
  if(parseInt(document.getElementById("eMeng").style.top,10) <= (docHeight - divHeight + parseInt(document.body.scrollTop,10)))
  {
  window.clearInterval(objTimer)
  objTimer = window.setInterval("resizeDiv()",1)
  }
  divTop = parseInt(document.getElementById("eMeng").style.top,10)
  document.getElementById("eMeng").style.top = divTop - 1
  }
  catch(e){}
  }
  function closeDiv()
  {
  document.getElementById('eMeng').style.visibility='hidden';
  if(objTimer) window.clearInterval(objTimer)
  }
  
  </Script>
  <DIV id=eMeng style="BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX:99999; LEFT: 0px; VISIBILITY: hidden; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: 300px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: 116px; BACKGROUND-COLOR: #c9d3f3">
  <p>弹窗内容</p>
  </DIV>
  
  </body>
  </html>
[/cce_js]

win2003服务器VPN设置

服务器端设置步骤:

打开我的电脑-管理-服务和应用程序-服务

1.禁用停止:windows自带防火墙(windows firewall/internet connection sharing(ICS))

2.自动开启:远程注册表服务(remote Registry)

3.自动开启:server服务(Server)

4.自动开启:router路由服务(Routing and Remote Access) 注意:此服务开启后FTP将失效

5.自动开启:Workstation服务

打开开始-管理工具-路由和远程访问

1.右击服务器-选择“配置并启用路由和远程访问”

2.选择自定义配置

3.选择VPN访问

4.选择IP选项卡:启用IP路由,允许基于IP的远程访问和请求拨号链接,选择静态地址池,选择一个IP段。

5.选择 IP路由选择-常规-右击选择新增路由协议增加NAT/基本防火墙

6.IP路由选择-NAT/基本防火墙-本地链接-右击选择NAT/基本防火墙选项卡:公用接口链接到internet,在此接口上启用NAT

打开我的电脑-管理-本地用户和组

1.在用户上右击,选择新用户

2.定义用户名,用户密码

3.在用户名在右击,选择属性,选择拨入选项卡:允许访问,不回拨,分配静态IP地址为IP段内地址。

win7 VPN客户端设置步骤

打开开始-控制面板-网络和Internet-网络和共享中心

1.选择设置新的链接或网络

2.选择连接到工作区

3.选择使用我的Internet连接(VPN)

4.输入VPN的internet地址和目标名称

5.打开更改适配器设置,双击链接VPN

 

 

 

php数组排序

数组排序:

1.sort 非关联数组字母顺序或数字大小排序:

[cce_php]

$products = array( ‘Tires’, ‘Oil’, ‘Spark Plugs’);
echo $products[0].”<br />”;
sort($products);
echo $products[0].”<br />”;

$num = array(10,50,1,20,30,60,55);
echo $num[0].”<br />”;
sort($num);
echo $num[0];

[/cce_php]

2.关联数组排序:

asort关联数组元素值排序

[cce_php]

$prices = array( ‘Tires’=>100,’Oil’ =>10 ,’Spark Plugs’ => 4);
foreach($prices as $key=>$value){
echo $key.”=>”.$value.”<br />”;
}
asort($prices);
echo “<br />”;
foreach($prices as $key=>$value){
echo $key.”=>”.$value.”<br />”;
}

[/cce_php]

ksort 关联数组按元素的键值排序

[cce_php]

$prices = array( ‘Tires’=>100,’Oil’ =>10 ,’Spark Plugs’ => 4);
foreach($prices as $key=>$value){
echo $key.”=>”.$value.”<br />”;
}
ksort($prices);
echo “<br />”;
foreach($prices as $key=>$value){
echo $key.”=>”.$value.”<br />”;
}

[/cce_php]

自定义数组排序,使用自定义函数返回值的正负来确定是升序还是降序

[cce_php]
<?php
$products = array( array( 'TIR', 'Tires', 100),
				   array( 'OIl', 'Oil', 10),
				   array( 'SPK', 'Spark Plugs', 4));
function compare($x, $y){
	if ($x[2] == $y[2]) {
		return 0;
		} else if ($x[2] < $y[2]) {
			return -1;
			} else {
				return 1;
				}
	}

usort ($products, 'compare');

while (list($product, $price) = each( $products)) {
	while (list($product1 , $price1) = each($products[$product])){
		echo "$product1 - $price1"."<br />";
		}
	
	}
?>
[/cce_php]

php数组操作

定义数组:

1.直接赋值

普通数组
$products = array(“Tires”, “Oil”, “Spark Plugs”);

关联数组
$prices = array(‘Tires’=>100, ‘Oil’=>10, ‘Spark Plugs’=>4);

2.range函数赋值

$numbers = range(1,10)  10个数据元素值为1-10

$numbers = range(1,10,2) 1-10中为奇数的数据元素值

 $numbers = range(‘a’,’z’) a到z数据元素值

3.数组首元素赋值

$numbers[0] = 1;
$number[‘tires’] = 10;

访问数组:

1.循环访问使用:
案例1 for(有序)

$numbers = range(‘a’,’z’);
for ($i = 0; $i < 26 ;$i++) {
echo $numbers[$i].”<br />”;
}

案例2 foreach(无序)
$products = array(“Tires”, “Oil”, “Spark Plugs”);
foreach ($products as $current){
echo $current;
}
$prices = array(‘Tires’=>100, ‘Oil’=>10, ‘Spark Plugs’=>4);
foreach ($prices as $key => $value) {
echo $key.”-“.$value.”<br />”;
}
案例三 while + each()
$prices = array(‘Tires’=>100, ‘Oil’=>10, ‘Spark Plugs’=>4);
while ($element = each($prices)){
echo $element[‘key’];
echo “-“;
echo $element[‘value’];
echo “<br>”;
}
案例四 while + list() +each()
$prices = array(‘Tires’=>100, ‘Oil’=>10, ‘Spark Plugs’=>4);
while (list($product, $price) = each($prices)) {
echo “$product – $price<br />”;
}

数组指针:

1.reset() 将数组指针定位到开头,重新遍历数组时需用此函数归位

多维数组遍历:

案例1

 $products = array ( array( 'TIR', 'Tires', 100), array('OIL', 'Oil', 10), array('SPK', 'Spark Plugs', 4)); echo $products[0][0]; for ($i=0; $i<3; $i++) { for ($j=0; $j<3; $j++){ echo $products[$i][$j]."\t"; } echo "<br />"; }

 案例二

 $products = array( array( 'Code'=> 'TIR', 'Description'=> 'Tires', 'Price'=> 100), array( 'Code'=> 'OIL', 'Description'=> 'Oil', 'Price'=>10), array( 'Code'=> 'SPK', 'Description'=> 'Spark Plugs', 'Price'=>4) ); for ($i=0; $i<3; $i++) { foreach( $products[$i] as $key => $value){ echo $value."\t"; } echo "<br />"; }

案例三:

[cce_php]
$products = array( array( 'Code'=> 'TIR', 'Description'=> 'Tires', 'Price'=> 100),
				   array( 'Code'=> 'OIL', 'Description'=> 'Oil', 'Price'=>10),
				   array( 'Code'=> 'SPK', 'Description'=> 'Spark Plugs', 'Price'=>4)
				   );
for ($i=0; $i<3; $i++) {
	while(list($key, $value) = each($products[$i])){
		echo $value."\t";		
		}
	echo "<br />";
[/cce_php]

 案例四

[cce_php]
	
$categories = array( array( array ( 'CAR_TIR', 'Tires', 100),
							array ( 'CAR_OIL', 'Oil', 10),
							array ( 'CAR_SPK', 'Spark Plugs', 4),
							),
					 array( array ( 'VAN_TIR', 'Tires', 120),
					 		array ( 'VAN_Oil', 'Oil', 12),
							array ( 'VAN_spk', 'Spark Plugs', 5),
							),
					 array( array ( 'TRK_TIR', 'Tires', 150),
					 		array ( 'TRK_OIl', 'Oil', 15),
							array ( 'TRK_SPK', 'Spark Plugs', 6)
						    )
				   );
for($i=0;$i<3;$i++){
	for($j=0;$j<3;$j++){
		for($h=0;$h<3;$h++){
			echo $categories[$i][$j][$h]."\t";			
			}
		echo "<br />";
		}
	echo "<br />";
	}
[/cce_php]

PHP文件操作函数

file_exists 判断文件是否存在:

file_exists(“$DOCUMENT_ROOT/../2015/orders.txt”)

filesize 确定文件大小:

filesize(“$DOCUMENT_ROOT/../2015/orders.txt”)

nl2br 将 \n 换行符转换成 html <br />:

nl2br(fread($fp,filesize(“$DOCUMENT_ROOT/../2015/orders.txt”)))

unlink删除文件

unlink(“$DOCUMENT_ROOT/../2015/orders.txt”)

文件指针:

rewind 文件指针复位到开始,

rewind($fp)

ftell 文件指针当前位置

ftell($fp)

fseek 文件指针移动到某位:

fseek($fp,字节)

文件锁定:

flock锁定文件:

操作值:LOCK_SH 读锁定 ; LOCK_EX 写锁定;

LOCK_UN 释放锁定;LOCK_NB 防止加锁时阻塞

flock($fp,操作值)

PHP读文件常用函数

fopen打开文件:

rb:二进制只读打开

feof判断文件指针;

读取一行:

1.fgets每次读取一行文字;

2.fgetss每次读取一行文字并清除其中的HTML和PHP标记;

3.fgetcsv每次读取一行文字并使用定界符将其分隔:

fgetcsv($fp,999,”\t”)

@$fp= fopen( “$DOCUMENT_ROOT/../2015/orders.txt”,’rb’);
if (!$fp) {
echo “<p><strong>No orders pending. please try again later.</strong></p>”;
exit;
}
while (!feof($fp)) {
$order = fgets($fp, 999);
echo $order.”<br />”;
}

读取整个文件:

1.readfile读取整个文件:

readfile(“$DOCUMENT_ROOT/../2015/orders.txt”);

2.fpassthur使用文件指针读取,未测试成功。

3.file将文件内容读取到一个数组中,每一行为一个数组原素:

$filearray = file(“$DOCUMENT_ROOT/../2015/orders.txt”)

[cce_php]

<?php
//Create short variable name
$DOCUMENT_ROOT =$_SERVER[‘DOCUMENT_ROOT’];
$orders = file(“$DOCUMENT_ROOT/../2015/orders.txt”);
$number_of_orders = count($orders);
if ($number_of_orders == 0) {
echo “<p><strong>No orders pending. Please try again later.</strong></p>”;
}
for($i=0; $i<$number_of_orders;$i++){
echo $orders[$i].”<br />”;
}
?>

[/cce_php]

读取每一个字符:

fgetc读取每一个字符:

while(!feof($fp)) {
$char = fgetc($fp);
echo ($char == “\n” ? “<br />” : $char);

}

读取任意长度内容:

fread读取到文件尾或包结束,未测试成功