首页 > php代码

php xml 保存到array数组

<?php

function xmlStringToArray($xmlString)
        {
        $xmlString = preg_replace('/<!--.*?-->/s','',$xmlString);
        $exitAfterManyLoohttp://www.phprm.com = 0;
        $xmlArray = array();
        $currentNode = &$xmlArray;
        $currentHierarchy = array();
        $currentDepth = 0;
        while($xmlString != '')
                {
                $exitAfterManyLoops++;
                if($exitAfterManyLoops > 300)
                        {
                        print "BREAK";
                        break;
                        }
                $xmlString = trim(substr($xmlString, strpos($xmlString, '<')));
                $thisNodeAscends = (substr($xmlString, 1, 1) == '/');
                $thisNodeDescends = (substr($xmlString, strpos($xmlString, '>') - 1, 1) != '/');
                $nodeName = substr($xmlString, 1, strpos($xmlString, ' ') -1);
                $openElement = substr($xmlString, strpos($xmlString, ' ') + 1);
                $openElement = substr($openElement, 0, strpos($openElement, '>') );
                if(substr($openElement, strlen($openElement) - 1, 1) == "/")
                        {
                        $openElement = substr($openElement, 0, strlen($openElement) - 1);
                        }

阅读全文

PHP :time(),date(),mktime()

日期与时间函数库{经常会忘却掉}
checkdate : 验证日期的正确性。
date : 将服务器的时间格式化。
strftime : 将服务器的时间本地格式化。
getdate : 获得时间及日期信息。
gettimeofday : 取得目前时间。
gmdate : 取得目前与 GMT 差后的时间。
easter_date : 计算复活节日期。
easter_days : 计算复活节与三月廿一日之间日期数。
mktime : 取得 UNIX 时间戳记。
gmmktime : 取得 UNIX 时间戳记的格林威治时间。
time : 取得目前时间的 UNIX 时间戳记。
microtime : 取得目前时间的 UNIX 时间戳记的百万分之一秒值。

阅读全文

php 读取视频文件播放时间长度

<?php
function BigEndian2Int($byte_word, $signed = false) {
$int_value = 0;
$byte_wordlen = strlen($byte_word);
for ($i = 0; $i < $byte_wordlen; $i++) {
$int_value += ord($byte_word{$i}) * pow(256, ($byte_wordlen - 1 - $i));
}
if ($signed) {
$sign_mask_bit = 0x80 << (8 * ($byte_wordlen - 1));
if ($int_value & $sign_mask_bit) {
$int_value = 0 - ($int_value & ($sign_mask_bit - 1));
}
}
return $int_value;
}
function getTime($name){
if(!file_exists($name)){
echo "文件不存在";exit;
}
$flv_data_length=filesize($name);
$fp = @fopen($name, 'rb');
$flv_header = fread($fp, 5);
fseek($fp, 5, SEEK_SET);
$frame_size_data_length =BigEndian2Int(fread($fp, 4));
$flv_header_frame_length = 9;
if ($frame_size_data_length > $flv_header_frame_length) {
fseek($fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR);
}
$duration = 0;
while ((ftell($fp) + 1) < $flv_data_length) {
$this_tag_header = fread($fp, 16);
$data_length = BigEndian2Int(substr($this_tag_header, 5, 3));
$timestamp = BigEndian2Int(substr($this_tag_header, 8, 3));
$next_offset = ftell($fp) - 1 + $data_length;
if ($timestamp > $duration) {
$duration = $timestamp;
}
fseek($fp, $next_offset, SEEK_SET);
}
fclose($fp);
return $duration;
}
if($_GET['submit'])
{
echo date('i分s秒',getTime($_GET['filepath'])/1000);
}
?>

阅读全文

PHP用socket模拟post之fsocketopen

地听说这个功能需求的时候,立即就蒙了,不骗大家!首先PHP的socket几乎都没使用过,其次没有听说过post还能用PHP的socket来模拟的呢!后来找了个案例看了看,才明白其实没有那么高深,只不过战地还不清楚post的原理和本质而已,其实本质就是发送给目的程序一个标志为post的协议串如下:

阅读全文

php ENCODE编码,DECODE解码

/**
 * @ string $str 要编码的字符串
 * @ string $ende 操作ENCODE编码,DECODE解码
 * @ string $key hash值
 * @return string
 */
function code($str, $ende, $key = '') {
 $coded = '';
 $keylength = strlen($key);
 $str = $ende == 'DECODE' ? base64_decode($str) : $str;
 for($i = 0; $i < strlen($str); $i += $keylength) {
  $coded .= substr($str, $i, $keylength) ^ $key;
 }
 $coded = $ende == 'ENCODE' ? str_replace('=', '', base64_encode($coded)) : $coded;
 return $coded;
}
我要们要 ENCODE编码,DECODE解码 只要设置$ende的参数就行了。

阅读全文

简单的目录删除程序

简单的目录删除程序
<?http://www.phprm.com
//目录删除函式
function del_DIR($directory){
$mydir=dir($directory);
while($file=$mydir->read()){
if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")){
del_DIR("$directory/$file");
}else{
if(($file!=".") AND ($file!="..")){
unlink("$directory/$file");
//echo "unlink $directory/$file ok
";
}
}
}
$mydir->close();
rmdir($directory);
//echo "rmdir $directory ok
";
}
?>

阅读全文

php 获取QQwry.dat真实IP地址

<?http://www.phprm.com
//===================================
//
// 功能:IP地址获取真实地址函数
// 参数:$ip - IP地址
//
//===================================
function convertip($ip) {
$dat_path = '../QQWry.Dat';       
if(!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/", $ip)) {
return 'IP Address Error';

if(!$fd = @fopen($dat_path, 'rb')){
return 'IP date file not exists or access denied';

$ip = explode('.', $ip);
$ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3]; 
$DataBegin = fread($fd, 4);
$DataEnd = fread($fd, 4);
$ipbegin = implode('', unpack('L', $DataBegin));
if($ipbegin < 0) $ipbegin += pow(2, 32);
$ipend = implode('', unpack('L', $DataEnd));
if($ipend < 0) $ipend += pow(2, 32);
$ipAllNum = ($ipend - $ipbegin) / 7 + 1;
$BeginNum = 0;
$EndNum = $ipAllNum; 
while($ip1num>$ipNum || $ip2num<$ipNum) {
$Middle= intval(($EndNum + $BeginNum) / 2);
fseek($fd, $ipbegin + 7 * $Middle);
$ipData1 = fread($fd, 4);
if(strlen($ipData1) < 4) {
fclose($fd);
return 'System Error';
}
$ip1num = implode('', unpack('L', $ipData1));
if($ip1num < 0) $ip1num += pow(2, 32);

阅读全文

php 文件下载安全

此脚本防止文件被链接到其他文件,因为这迫使脚本文件被下载之前在下载开始。这个脚本是非常重要的高度机密的文件。

在此脚本,filter_var()用于过滤文件和有效的字符串验证的文件,该文件使用过滤器将下载的文件FILTER_SANITIZE_STRING。

阅读全文