当前位置: 编程技术>php
本页文章导读:
▪PHP5中使用DOM控制XML实现代码
下面的例子简单的演示了DOM对XML的操作,详细解释请看代码中的注释 代码如下: <? /************************************************ ** use XML in PHP5 ** reference site: ** http://cn.php.net/manual/zh/ref.dom.php ** the.........
▪PHP 金额数字转换成英文
代码如下:<?php $num=1220.01; echo fmoney($num);//结果:1,220.21 echo umoney($num); //结果:ONE THOUSAND AND TWO HUNDRED TWENTY DOLLARS AND TWENTY-ONE CENTS ONLY echo umoney($num,"rmb"); //结果:ONE THOUSAND AND TWO HUNDRED TWENTY YUA.........
▪php源码加密 仿微盾PHP加密专家(PHPCodeLock)
代码如下:function T_rndstr($length=""){//返回随机字符串 $str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; if($length==""){ return str_shuffle($str); }else{ return substr(str_shuffle($str),-$length); } } $T_k1=T_rndstr();//随.........
[1]PHP5中使用DOM控制XML实现代码
来源: 互联网 发布时间: 2013-11-30
下面的例子简单的演示了DOM对XML的操作,详细解释请看代码中的注释
<?
/************************************************
** use XML in PHP5
** reference site:
** http://cn.php.net/manual/zh/ref.dom.php
** the follow codes need PHP5 support
*************************************************/
//首先要创建一个DOMDocument对象
$dom = new DomDocument();
//然后载入XML文件
$dom -> load("test.xml");
//输出XML文件
//header("Content-type: text/xml;charset=gb2312");
//echo $dom -> saveXML();
//保存XML文件,返回值为int(文件大小,以字节为单位)
//$dom -> save("newfile.xml");
echo "<hr/>取得所有的title元素:<hr/>";
$titles = $dom -> getElementsByTagName("title");
foreach ($titles as $node){
echo $node -> textContent . "<br/>";
//这样也可以
//echo $node->firstChild->data . "<br/>";
}
/*
echo "<hr/>从根结点遍历所有结点:<br/>";
foreach ($dom->documentElement->childNodes as $items) {
//如果节点是一个元素(nodeType == 1)并且名字是item就继续循环
if ($items->nodeType == 1 && $items->nodeName == "item") {
foreach ($items->childNodes as $titles) {
//如果节点是一个元素,并且名字是title就打印它.
if ($titles->nodeType == 1 && $titles->nodeName == "title") {
print $titles->textContent . "\n";
}
}
}
}
*/
//使用XPath查询数据
echo "<hr/>使用XPath查询的title节点结果:<hr/>";
$xpath = new domxpath($dom);
$titles = $xpath->query("/rss/channel/item/title");
foreach ($titles as $node){
echo $node->textContent."<br/>";
}
/*
这样和使用getElementsByTagName()方法差不多,但是Xpath要强大的多
深入一点可能是这样:
/rss/channel/item[position() = 1]/title 返回第一个item元素的所有
/rss/channel/item/title[@id = '23'] 返回所有含有id属性并且值为23的title
/rss/channel/&folder&/title 返回所有articles元素下面的title(译者注:&folder&代表目录深度)
*/
//向DOM中写入新数据
$item = $dom->createElement("item");
$title = $dom->createElement("title");
$titleText = $dom->createTextNode("title text");
$title->appendChild($titleText);
$item->appendChild($title);
$dom->documentElement->getElementsByTagName('channel')->item(0)->appendChild($item);
//从DOM中删除节点
//$dom->documentElement->RemoveChild($dom->documentElement->getElementsByTagName("channel")->item(0));
//或者使用xpath查询出节点再删除
//$dom->documentElement->RemoveChild($xpath->query("/rss/channel")->item(0));
//$dom->save("newfile.xml");
//从DOM中修改节点数据
//修改第一个title的文件
//这个地方比较笨,新创建一个节点,然后替换旧的节点。如果哪位朋友有其他好的方法请一定要告诉我
$firstTitle = $xpath->query("/rss/channel/item/title")->item(0);
$newTitle = $dom->createElement("title");
$newTitle->appendChild(new DOMText("This's the new title text!!!"));
$firstTitle->parentNode->replaceChild($newTitle, $firstTitle);
//修改属性
//$firstTitle = $xpath->query("/rss/channel/item/title")->item(0);
//$firstTitle->setAttribute("orderby", "4");
$dom->save("newfile.xml");
echo "<hr/><a href=/index.html"newfile.xml\">查看newfile.xml</a>";
//下面的代码获得并解析php.net的首页,将返第一个title元素的内容。
/*
$dom->loadHTMLFile("http://www.php.net/");
$title = $dom->getElementsByTagName("title");
print $title->item(0)->textContent;
*/
?>
下面是test.xml文件代码:
<?xml version="1.0" encoding="gb2312"?>
<rss version="2.0">
<channel>
<title>javascript</title>
<link>http://blog.csdn.net/zhongmao/category/29515.aspx</link>
<description>javascript</description>
<language>zh-chs</language>
<generator>.text version 0.958.2004.2001</generator>
<item>
<creator>zhongmao</creator>
<title orderby="1">out put excel used javascript</title>
<link>http://blog.csdn.net/zhongmao/archive/2004/09/15/105385.aspx</link>
<pubdate>wed, 15 sep 2004 13:32:00 gmt</pubdate>
<guid>http://blog.csdn.net/zhongmao/archive/2004/09/15/105385.aspx</guid>
<comment>http://blog.csdn.net/zhongmao/comments/105385.aspx</comment>
<comments>http://blog.csdn.net/zhongmao/archive/2004/09/15/105385.aspx#feedback</comments>
<comments>2</comments>
<commentrss>http://blog.csdn.net/zhongmao/comments/commentrss/105385.aspx</commentrss>
<ping>http://blog.csdn.net/zhongmao/services/trackbacks/105385.aspx</ping>
<description>test description</description>
</item>
<item>
<creator>zhongmao</creator>
<title orderby="2">out put word used javascript</title>
<link>http://blog.csdn.net/zhongmao/archive/2004/08/06/67161.aspx</link>
<pubdate>fri, 06 aug 2004 16:33:00 gmt</pubdate>
<guid>http://blog.csdn.net/zhongmao/archive/2004/08/06/67161.aspx</guid>
<comment>http://blog.csdn.net/zhongmao/comments/67161.aspx</comment>
<comments>http://blog.csdn.net/zhongmao/archive/2004/08/06/67161.aspx#feedback</comments>
<comments>0</comments>
<commentrss>http://blog.csdn.net/zhongmao/comments/commentrss/67161.aspx</commentrss>
<ping>http://blog.csdn.net/zhongmao/services/trackbacks/67161.aspx</ping>
<description>test word description</description>
</item>
<item>
<creator>zhongmao</creator>
<title orderby="3">xmlhttp</title>
<link>http://blog.csdn.net/zhongmao/archive/2004/08/02/58417.aspx</link>
<pubdate>mon, 02 aug 2004 10:11:00 gmt</pubdate>
<guid>http://blog.csdn.net/zhongmao/archive/2004/08/02/58417.aspx</guid>
<comment>http://blog.csdn.net/zhongmao/comments/58417.aspx</comment>
<comments>http://blog.csdn.net/zhongmao/archive/2004/08/02/58417.aspx#feedback</comments>
<comments>0</comments>
<commentrss>http://blog.csdn.net/zhongmao/comments/commentrss/58417.aspx</commentrss>
<ping>http://blog.csdn.net/zhongmao/services/trackbacks/58417.aspx</ping>
<description>xmlhttpaaa asd bb cc dd</description>
</item>
</channel>
</rss>
代码如下:
<?
/************************************************
** use XML in PHP5
** reference site:
** http://cn.php.net/manual/zh/ref.dom.php
** the follow codes need PHP5 support
*************************************************/
//首先要创建一个DOMDocument对象
$dom = new DomDocument();
//然后载入XML文件
$dom -> load("test.xml");
//输出XML文件
//header("Content-type: text/xml;charset=gb2312");
//echo $dom -> saveXML();
//保存XML文件,返回值为int(文件大小,以字节为单位)
//$dom -> save("newfile.xml");
echo "<hr/>取得所有的title元素:<hr/>";
$titles = $dom -> getElementsByTagName("title");
foreach ($titles as $node){
echo $node -> textContent . "<br/>";
//这样也可以
//echo $node->firstChild->data . "<br/>";
}
/*
echo "<hr/>从根结点遍历所有结点:<br/>";
foreach ($dom->documentElement->childNodes as $items) {
//如果节点是一个元素(nodeType == 1)并且名字是item就继续循环
if ($items->nodeType == 1 && $items->nodeName == "item") {
foreach ($items->childNodes as $titles) {
//如果节点是一个元素,并且名字是title就打印它.
if ($titles->nodeType == 1 && $titles->nodeName == "title") {
print $titles->textContent . "\n";
}
}
}
}
*/
//使用XPath查询数据
echo "<hr/>使用XPath查询的title节点结果:<hr/>";
$xpath = new domxpath($dom);
$titles = $xpath->query("/rss/channel/item/title");
foreach ($titles as $node){
echo $node->textContent."<br/>";
}
/*
这样和使用getElementsByTagName()方法差不多,但是Xpath要强大的多
深入一点可能是这样:
/rss/channel/item[position() = 1]/title 返回第一个item元素的所有
/rss/channel/item/title[@id = '23'] 返回所有含有id属性并且值为23的title
/rss/channel/&folder&/title 返回所有articles元素下面的title(译者注:&folder&代表目录深度)
*/
//向DOM中写入新数据
$item = $dom->createElement("item");
$title = $dom->createElement("title");
$titleText = $dom->createTextNode("title text");
$title->appendChild($titleText);
$item->appendChild($title);
$dom->documentElement->getElementsByTagName('channel')->item(0)->appendChild($item);
//从DOM中删除节点
//$dom->documentElement->RemoveChild($dom->documentElement->getElementsByTagName("channel")->item(0));
//或者使用xpath查询出节点再删除
//$dom->documentElement->RemoveChild($xpath->query("/rss/channel")->item(0));
//$dom->save("newfile.xml");
//从DOM中修改节点数据
//修改第一个title的文件
//这个地方比较笨,新创建一个节点,然后替换旧的节点。如果哪位朋友有其他好的方法请一定要告诉我
$firstTitle = $xpath->query("/rss/channel/item/title")->item(0);
$newTitle = $dom->createElement("title");
$newTitle->appendChild(new DOMText("This's the new title text!!!"));
$firstTitle->parentNode->replaceChild($newTitle, $firstTitle);
//修改属性
//$firstTitle = $xpath->query("/rss/channel/item/title")->item(0);
//$firstTitle->setAttribute("orderby", "4");
$dom->save("newfile.xml");
echo "<hr/><a href=/index.html"newfile.xml\">查看newfile.xml</a>";
//下面的代码获得并解析php.net的首页,将返第一个title元素的内容。
/*
$dom->loadHTMLFile("http://www.php.net/");
$title = $dom->getElementsByTagName("title");
print $title->item(0)->textContent;
*/
?>
下面是test.xml文件代码:
代码如下:
<?xml version="1.0" encoding="gb2312"?>
<rss version="2.0">
<channel>
<title>javascript</title>
<link>http://blog.csdn.net/zhongmao/category/29515.aspx</link>
<description>javascript</description>
<language>zh-chs</language>
<generator>.text version 0.958.2004.2001</generator>
<item>
<creator>zhongmao</creator>
<title orderby="1">out put excel used javascript</title>
<link>http://blog.csdn.net/zhongmao/archive/2004/09/15/105385.aspx</link>
<pubdate>wed, 15 sep 2004 13:32:00 gmt</pubdate>
<guid>http://blog.csdn.net/zhongmao/archive/2004/09/15/105385.aspx</guid>
<comment>http://blog.csdn.net/zhongmao/comments/105385.aspx</comment>
<comments>http://blog.csdn.net/zhongmao/archive/2004/09/15/105385.aspx#feedback</comments>
<comments>2</comments>
<commentrss>http://blog.csdn.net/zhongmao/comments/commentrss/105385.aspx</commentrss>
<ping>http://blog.csdn.net/zhongmao/services/trackbacks/105385.aspx</ping>
<description>test description</description>
</item>
<item>
<creator>zhongmao</creator>
<title orderby="2">out put word used javascript</title>
<link>http://blog.csdn.net/zhongmao/archive/2004/08/06/67161.aspx</link>
<pubdate>fri, 06 aug 2004 16:33:00 gmt</pubdate>
<guid>http://blog.csdn.net/zhongmao/archive/2004/08/06/67161.aspx</guid>
<comment>http://blog.csdn.net/zhongmao/comments/67161.aspx</comment>
<comments>http://blog.csdn.net/zhongmao/archive/2004/08/06/67161.aspx#feedback</comments>
<comments>0</comments>
<commentrss>http://blog.csdn.net/zhongmao/comments/commentrss/67161.aspx</commentrss>
<ping>http://blog.csdn.net/zhongmao/services/trackbacks/67161.aspx</ping>
<description>test word description</description>
</item>
<item>
<creator>zhongmao</creator>
<title orderby="3">xmlhttp</title>
<link>http://blog.csdn.net/zhongmao/archive/2004/08/02/58417.aspx</link>
<pubdate>mon, 02 aug 2004 10:11:00 gmt</pubdate>
<guid>http://blog.csdn.net/zhongmao/archive/2004/08/02/58417.aspx</guid>
<comment>http://blog.csdn.net/zhongmao/comments/58417.aspx</comment>
<comments>http://blog.csdn.net/zhongmao/archive/2004/08/02/58417.aspx#feedback</comments>
<comments>0</comments>
<commentrss>http://blog.csdn.net/zhongmao/comments/commentrss/58417.aspx</commentrss>
<ping>http://blog.csdn.net/zhongmao/services/trackbacks/58417.aspx</ping>
<description>xmlhttpaaa asd bb cc dd</description>
</item>
</channel>
</rss>
[2]PHP 金额数字转换成英文
来源: 互联网 发布时间: 2013-11-30
代码如下:
<?php
$num=1220.01;
echo fmoney($num);//结果:1,220.21
echo umoney($num);
//结果:ONE THOUSAND AND TWO HUNDRED TWENTY DOLLARS AND TWENTY-ONE CENTS ONLY
echo umoney($num,"rmb");
//结果:ONE THOUSAND AND TWO HUNDRED TWENTY YUAN AND TWENTY-ONE FEN ONLY
//define
//格式化货币
function fmoney($num) {
$num=0+$num;
$num = sprintf("%.02f",$num);
if(strlen($num) <= 6) return $num;
//从最后开始算起,每3个数它加一个","
for($i=strlen($num)-1,$k=1, $j=100; $i >= 0; $i--,$k++) {
$one_num = substr($num,$i,1);
if($one_num ==".") {
$numArray[$j--] = $one_num;
$k=0;
continue;
}
if($k%3==0 and $i!=0) {
//如果正好只剩下3个数字,则不加','
$numArray[$j--] = $one_num;
$numArray[$j--] = ",";
$k=0;
} else {
$numArray[$j--]=$one_num;
}
}
ksort($numArray);
return join("",$numArray);
}
function umoney($num,$type="usd") {
global $numTable,$commaTable,$moneyType;
//global $numTable;
$numTable[0]="ZERO ";
$numTable[1]="ONE ";
$numTable[2]="TWO ";
$numTable[3]="THREE ";
$numTable[4]="FOUR ";
$numTable[5]="FIVE ";
$numTable[6]="SIX ";
$numTable[7]="SEVEN ";
$numTable[8]="EIGHT ";
$numTable[9]="NINE ";
$numTable[10]="TEN ";
$numTable[11]="ELEVEN ";
$numTable[12]="TWELVE ";
$numTable[13]="THIRTEEN ";
$numTable[14]="FOURTEEN ";
$numTable[15]="FIFTEEN ";
$numTable[16]="SIXTEEN ";
$numTable[17]="SEVENTEEN ";
$numTable[18]="EIGHTEEN ";
$numTable[19]="NINETEEN ";
$numTable[20]="TWENTY ";
$numTable[30]="THIRTY ";
$numTable[40]="FORTY ";
$numTable[50]="FIFTY ";
$numTable[60]="SIXTY ";
$numTable[70]="SEVENTY ";
$numTable[80]="EIGHTY ";
$numTable[90]="NINETY ";
$commaTable[0]="HUNDRED ";
$commaTable[1]="THOUSAND ";
$commaTable[2]="MILLION ";
$commaTable[3]="MILLIARD ";
$commaTable[4]="BILLION ";
$commaTable[5]="????? ";
//单位
$moneyType["usd"]="DOLLARS ";
$moneyType["usd_1"]="CENTS ONLY";
$moneyType["rmb"]="YUAN ";
$moneyType["rmb_1"]="FEN ONLY";
if($type=="") $type="usd";
$fnum = fmoney($num);
$numArray = explode(",",$fnum);
$resultArray = array();
$k=0;
$cc=count($numArray);
for($i = 0; $i < count($numArray); $i++) {
$num_str = $numArray[$i];
//echo "<br>";
//小数位的处理400.21
if(eregi("\.",$num_str)) {
$dotArray = explode(".",$num_str);
if($dotArray[1] != 0) {
$resultArray[$k++]=format3num($dotArray[0]+0);
$resultArray[$k++]=$moneyType[strtolower($type)];
$resultArray[$k++]="AND ";
$resultArray[$k++]=format3num($dotArray[1]+0);
$resultArray[$k++]=$moneyType[strtolower($type)."_1"];
} else {
$resultArray[$k++]=format3num($dotArray[0]+0);
$resultArray[$k++]=$moneyType[strtolower($type)];
}
} else {
//非小数位的处理
if(($num_str+0)!=0) {
$resultArray[$k++]=format3num($num_str+0);
$resultArray[$k++]=$commaTable[--$cc];
//判断:除小数外其余若不为零则加and
for($j=$i; $j <= $cc; $j++) {
//echo "<br>";
//echo $numArray[$j];
if($numArray[$j] !=0) {
$resultArray[$k++]="AND ";
break;
}
}
}
}
}
return join("",$resultArray);
}
function format3num($num) {
global $numTable,$commaTable;
$numlen = strlen($num);
for($i = 0,$j = 0;$i < $numlen; $i++) {
$bitenum[$j++] = substr($num,$i,1);
}
if($num==0) return "";
if($numlen == 1) return $numTable[$num];
if($numlen == 2) {
if($num <= 20) return $numTable[$num];
//第一位不可能零
if($bitenum[1]==0) {
return $numTable[$num];
} else {
return trim($numTable[$bitenum[0]*10])."-".$numTable[$bitenum[1]];
}
}
//第一个不可能为零
if($numlen == 3) {
if($bitenum[1]==0 && $bitenum[2]==0) {
//100
return $numTable[$bitenum[0]].$commaTable[0];
} elseif($bitenum[1]==0) {
//102
return $numTable[$bitenum[0]].$commaTable[0].$numTable[$bitenum[2]];
} elseif ($bitenum[2]==0) {
//120
return $numTable[$bitenum[0]].$commaTable[0].$numTable[$bitenum[1]*10];
} else {
//123
return $numTable[$bitenum[0]].$commaTable[0].trim($numTable[$bitenum[1]*10])."-".$numTable[$bitenum[2]];
}
}
return $num;
}
?>
[3]php源码加密 仿微盾PHP加密专家(PHPCodeLock)
来源: 互联网 发布时间: 2013-11-30
代码如下:
function T_rndstr($length=""){//返回随机字符串
$str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
if($length==""){
return str_shuffle($str);
}else{
return substr(str_shuffle($str),-$length);
}
}
$T_k1=T_rndstr();//随机密匙1
$T_k2=T_rndstr();//随机密匙2
$vstr=file_get_contents("xk/xk/index.php");//要加密的文件
$v1=base64_encode($vstr);
$c=strtr($v1,$T_k1,$T_k2);//根据密匙替换对应字符。
$c=$T_k1.$T_k2.$c;
$q=T_rndstr();
$isqs=1;//1 取随机字符串为变量名 2 大写O与数字0组成基本变量
if($isqs=="1"){
$q1=substr($q,2,3);
$q2=substr($q,10,10);
$q3=substr($q,20,12);
$q4=substr($q,30,10);
$q5=substr($q,40,8);
$q6=substr($q,5,5);
}else{
$q1="O00O0O";
$q2="O0O000";
$q3="O0OO00";
$q4="OO0O00";
$q5="OO0000";
$q6="O00OO0";
}
$keystr=urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");
/* 全字符串
n1zb/ma5\vt0i28-pxuqy*6lrkdg9_ehcswo4+f37j
base64_decode //$q1
strtr //$q2
substr
*/
$s='$'.$q6.'=urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");$'.$q1.'=$'.$q6.'{3}.$'.$q6.'{6}.$'.$q6.'{33}.$'.$q6.'{30};$'.$q3.'=$'.$q6.'{33}.$'.$q6.'{10}.$'.$q6.'{24}.$'.$q6.'{10}.$'.$q6.'{24};$'.$q4.'=$'.$q3.'{0}.$'.$q6.'{18}.$'.$q6.'{3}.$'.$q3.'{0}.$'.$q3.'{1}.$'.$q6.'{24};$'.$q5.'=$'.$q6.'{7}.$'.$q6.'{13};$'.$q1.'.=$'.$q6.'{22}.$'.$q6.'{36}.$'.$q6.'{29}.$'.$q6.'{26}.$'.$q6.'{30}.$'.$q6.'{32}.$'.$q6.'{35}.$'.$q6.'{26}.$'.$q6.'{30};eval($'.$q1.'("'.base64_encode('$'.$q2.'="'.$c.'";eval(\'?>\'.$'.$q1.'($'.$q3.'($'.$q4.'($'.$q2.',$'.$q5.'*2),$'.$q4.'($'.$q2.',$'.$q5.',$'.$q5.'),$'.$q4.'($'.$q2.',0,$'.$q5.'))));').'"));';
仿照 微盾PHP加密专家(PHPCodeLock)
最新技术文章: