PHP输出函数

一般输出echo,格式输出printf

b:整数转二进制;

c:整数转字符;

d:整数转小数;

f:双精度转浮点数;

o:整数转八进制;

s:字符串转字符串;

u:整数转非指定整数;

x:整数转带小写字母的十六进制数

X:整数转带大写字母的十六进制数

[cce_php]

<?php
$test_a = 12;
$test_b = “xiaomin”;

//直接输出
echo “1name:$test_b”.”<br />”.”number:$test_a<br />”;

//字串格式化输出
printf(“2name:%s<br />number:%s<br />”,$test_b,$test_a);

//字串定义先后顺序(%位置\$)
printf(“3name:%2\$s<br />number:%1\$s<br />”,$test_a,$test_b);

//number三位小数输出 f代表浮点数
printf(“4name:%s<br />number:%.3f<br />”,$test_b,$test_a);

//显示%需要两个%%
printf(“5name:%s<br />number:%s%%<br />”,$test_b,$test_a);

?>

[/cce_php]

字符串格式化函数

清除多余字符:

trim清除开始和结束,ltrim清除开始,rtrim清除结束。

trim 函数去除字串开始和结束的空格,换行符或回车符(\n或\r),水平和垂直制表符(\t和\x0b)和字串结速符(\0),设定第二个参数会过滤自定义字符。

[cce_php]

<?php
$test = ” my name is “;
echo $test.”aa<br />”;
$test_a = trim($test);

echo $test_a.”aa<br />”;

?>

[/cce_php]

 

HTML格式化函数:nl2br 将字串中的换行符(\n)替换为<br />

[cce_php]

<?php
$test = ”
Chinadaily.com.cn is the largest English porta
l in China, providing news, business information,
BBS, learning materials. The Website has channels
as China.”;
echo nl2br($test);

?>

[/cce_php]

改变字母大小写:

[cce_php]

<?php
$test_a = “My name is Xiaomin “;
$test_b = “my name is xiaomin”;
//将字符串转为大写
echo strtoupper($test_a).”<br />”;

//将字串转为小写
echo strtolower($test_a).”<br />”;

//如果第一个是字母就将首字母转为大写
echo ucfirst($test_b).”<br />”;

//字符串每一个单词首字母大写
echo ucwords($test_b).”<br />”;
?>

[/cce_php]

为存入数库库需要的格式化:

引号,单引和双引,反斜杠\,NULL字符在数据库中会被当成控制符

addslashes函数会自动在以上字符前加转义符\

stripslashes函数会自动把以上字符前的转义符去掉

 

PHP邮件函数mail使用案例

[cce_php]

<?php
//create short variable names
$name=$_post[‘name’];
$email=$_post[’email’];
$feedback=$_post[‘feedback’];

//set up some static information

$toaddress = “thqe@qq.com”;
$subject = “Feedback from web site”;
$mailcontent=”Customer name:”.$name.”\n”.”Customer email:”.$email.”\n”.”Customer comments:\n”.$feedback.”\n”;

$fromaddress = “From: thqe@qq.com”;

//invoke mail() function to send mail
mail($toaddress,$subject,$mailcontent,$fromaddress);
?>
<html>
<head>
<title>Bob’s Auto Parts – Feedback Submitted</title>
</head>
<body>
<h1>Feedback submitted</h1>
<p>Your feedback has been sent.</p>
</body>
</html>

[/cce_php]

统计数组中元素个数

统计数组总元素个数count或sizeof

[cce_php]

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

echo “<br />”;

echo sizeof($array);
?>

[/cce_php]

统计某一个数组元素在数组中出现的次数:

array_count_values

[cce_php]

<?php
$array = array( “a”,”b”,”c”,1,2,3,3,”a”,”a”);
$array_num = array_count_values($array);
while (list($key,$value) = each($array_num)){

echo “$key => $value <br />”;
}

[/cce_php]

 

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

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