php解析 JSON 数据
代码如下 | 复制代码 |
$json_string='{"id":1,"name":"foo","email":"foo@foobar.com","interest":["wordpress","php"]} '; $obj=json_decode($json_string); echo $obj->name; //prints foo echo $obj->interest[1]; //prints php |
,同时windows换行符是"rn",linux换行符是"n"
PHP记录IP的函数是 $_SERVER["REMOTE_ADDR"]
PHP获取当前时间函数date("Y-m-d H:i:s", time())
PHP获取来路网址函数$_SERVER['HTTP_REFERER'] 首先要判断其是否为空值,即用isset进行判断,比如我们直接从浏览器敲入网址则不会有来路网址记录,最后代码很简单,如下:
代码如下 | 复制代码 |
$ip = $_SERVER["REMOTE_ADDR"]; |
先来看看效果
代码如下
index.html文件,保保存成index.htm
代码如下 | 复制代码 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <script type="text/网页特效" src="jquery-1.2.1.pack.js"></script> <style type="text/css教程"> .suggestionsBox { </head> <body>
</body> |
php文件
代码如下 | 复制代码 |
<?php } |
sql.sql把这里复制保存到你的数据库教程
代码如下 | 复制代码 |
-- phpMyAdmin SQL Dump SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
-- -- -------------------------------------------------------- -- CREATE TABLE IF NOT EXISTS `countries` ( -- INSERT INTO `countries` (`id`, `value`) VALUES |
注:里面有个jquery文件没有放上来,大家可以到http://down.111cn.net下载或者到百度搜索
由于工作需要我找了二个时间日期控制,这个不用js只要php实现的,因为要带参考查询所以操作了操作,有需要的朋友可以参考一下哦,我自己用的是第二个,所以第二个己作了修改。<?php教程
class Calendar
{
var $month;
var $year;function __construct($year,$month)
{
$this->year=$year;
$this->month=$month;
}function endday()
{
$daydate=date("d",mktime(0,0,0,$this->month,35,$this->year));
$endday=35-$daydate;
return $endday;
}
function oneday_week()
{
$oneday_week=date("w",mktime(0,0,0,$this->month,1,$this->year));
return $oneday_week;
}
function title_link()
{
if(!isset($this->month) && !isset($this->year))
{
$this->year = date("Y");
$this->month = date("m");
}
$lastmonth=$this->month-1;
$nextmonth=$this->month+1;
$lastyear=$this->year;
$nextyear=$this->year;if($this->month <= 1)
{
$lastmonth=12;
$nextmonth=$this->month+1;
$lastyear=$this->year-1;
$nextyear=$this->year;
}
elseif ($this->month >= 12)
{
$lastmonth=$this->month-1;
$nextmonth=1;
$lastyear=$this->year;
$nextyear=$this->year+1;
}$str ="<td colspan='2'><div align='center'><a href=$PHP_SELF?year=".$lastyear."&month=".$lastmonth."&><<<</a></div></td>";
$str.="<td colspan='3'><div align='center'>".$this->year."--".$this->month."</div></td>";
$str.="<td colspan='2'><div align='center'><a href=$PHP_SELF?year=".$nextyear."&month=".$nextmonth."&>>>></a></div></td>";
return $str;
}
function Show_Calendar()
{
echo "<table width='181' border=5><tr class='tr.title'>".$this->title_link()."</tr><tr>";
$weekarray=array("日","一","二","三","四","五","六");
for($k=0;$k<=6;$k++)
{
echo "<td><div align='center'>".$weekarray[$k]."</div></td>";
}
echo "</tr>";
for($i=0;$i<=5;$i++)
{
echo "<tr>";
for($j=1;$j<=7;$j++)
{
$math=( $j - $this->oneday_week() ) + 7 * $i;
echo "<td><div align='center'>";
if($math <= $this->endday() and $math>=1)
{
echo $math;
}
echo "</div></td>";
}
echo "</tr>";
}
echo "</table>";
}
}/*$calendar=new Calendar($_GET['year'],$_GET['month']);
//$calendar->month=$_GET['month'];
//$calendar->year=$_GET['year'];
$calendar->Show_Calendar();*/
//第二个?>
实例二
<?php
header("content-type:text/html;charset=utf-8");
?>
<meta http-equiv="content-type" content="text/html;charset=utf-8"><link href="statics/css教程/zhaoshang.css" rel="stylesheet" type="text/css">
<div class="rili">
<?php
if(!empty($_GET)){
$year = isset($_GET['year'])?$_GET['year']:date('y');
$month = isset($_GET['month'])?$_GET['month']:date('m');
$day = isset($_GET['day'])?$_GET['day']:date('d');
}
if(empty($year)){
$year = date('Y');
}
if(empty($month)){
$month = date('m');
}if(empty($month)){
$days = date('d');
}$start_weekday = date('w',mktime(0,0,0,$month,1,$year));
//echo $start_weekday;
$days = date('t',mktime(0,0,0,$month,1,$year));
//echo $days;
$week = array('日','一','二','三','四','五','六');
$i = 0;
$k = 1;
$j = 0;
echo '<table >';
echo '<tr><td colspan = 7 style ="text-align:center; width:250px; background:#d5e5f6; border-bottom:1px solid #333366;">'.$year.'年'.$month.'月'.'</td></tr>';
echo '<tr>';
for($i = 0;$i < 7;$i++){
echo '<td>'.$week[$i].'</td>';
}
echo '</tr>';
echo '<tr>';
for($j = 0;$j < $start_weekday;$j++){
echo '<td style="color:#f1f8fc;">'.$j.'</td>';
}
while($k <= $days){
if($k == $day){
echo '<td style="color:red"><a href="?year='.$year.'&month='.$month.'&day='.$k.'"><span style="color:red">'.$k.'</span></a></td>';
}else{
echo '<td><a href="?year='.$year.'&month='.$month.'&day='.$k.'">'.$k.'</a></td>';
}
if(($j+1) % 7 == 0){
echo '</tr><tr>';
}
$j++;
$k++;
}
while($j % 7 != 0){
echo '<td style="color:#f1f8fc;">'.$j.'</td>';
$j++;
}
echo '</tr>';echo '<tr style="background:#d5e5f6;">';
echo "<td><a href=?".lastYear($year,$month).">".'<<'.'</a></td>';
echo "<td><a href=?".lastMonth($year,$month).">".'<'.'</a></td>';
echo '<td colspan = 3 style="width:105px;" >';
echo '<form name = "myform" method = "GET">';
echo '<select name = year class="year">';
for($start_year = 1970;$start_year<2039;$start_year++){
$selected='';
if( $year== $start_year ) { $selected='selected'; }
echo '<option value ='. $start_year.' '.$selected.'>'.$start_year.'</option>'." nt";
}
echo '</select>';
echo '<select name = month class="month">';
for($start_month = 1;$start_month<=12;$start_month++){
$selected='';
if( $month== $start_month ) { $selected='selected';}
echo '<option value = '.$start_month.' '.$selected.'>'.$start_month.'</option>'." nt";
}
echo '</select>';
/*echo '月';*/
/*echo '<input type = "submit" name = "search" value = "查询">';*/
echo '</form>';
echo '</td>';
echo "<td><a href=?".nextYear($year,$month).">".'>>'.'</a></td>';
echo "<td><a href=?".nextMonth($year,$month).">".'>'.'</a></td>';
echo '</tr>';
echo '</table>';function lastYear($year,$month){
$year = $year-1;
return "year=$year&month=$month";
}
function lastMonth($year,$month){
if($month == 1){
$year = $year -1;
$month = 12;
}else{
$month--;
}
return "year=$year&month=$month";
}
function nextYear($year,$month){
$year = $year+1;
return "year=$year&month=$month";
}
function nextMonth($year,$month){
if($month == 12){
$year = $year +1;
$month = 1;
}else {
$month++;
}
return "year=$year&month=$month";
}?>
</div>
<?php教程
/**
* 转化 为 /
*
* @param string $path 路径
* @return string 路径
*/
function dir_path($path) {
$path = str_replace('\', '/', $path);
if(substr($path, -1) != '/') $path = $path.'/';
return $path;
}
/**
* 创建目录
*
* @param string $path 路径
* @param string $mode 属性
* @return string 如果已经存在则返回true,否则为flase
*/
function dir_create($path, $mode = 0777) {
if(is_dir($path)) return TRUE;
$ftp_enable = 0;
$path = dir_path($path);
$temp = explode('/', $path);
$cur_dir = '';
$max = count($temp) - 1;
for($i=0; $i<$max; $i++) {
$cur_dir .= $temp[$i].'/';
if (@is_dir($cur_dir)) continue;
@mkdir($cur_dir, 0777,true);
@chmod($cur_dir, 0777);
}
return is_dir($path);
}
/**
* 拷贝目录及下面所有文件
*
* @param string $fromdir 原路径
* @param string $todir 目标路径
* @return string 如果目标路径不存在则返回false,否则为true
*/
function dir_copy($fromdir, $todir) {
$fromdir = dir_path($fromdir);
$todir = dir_path($todir);
if (!is_dir($fromdir)) return FALSE;
if (!is_dir($todir)) dir_create($todir);
$list = glob($fromdir.'*');
if (!empty($list)) {
foreach($list as $v) {
$path = $todir.basename($v);
if(is_dir($v)) {
dir_copy($v, $path);
} else {
copy($v, $path);
@chmod($path, 0777);
}
}
}
return TRUE;
}
/**
* 转换目录下面的所有文件编码格式
*
* @param string $in_charset 原字符集
* @param string $out_charset 目标字符集
* @param string $dir 目录地址
* @param string $fileexts 转换的文件格式
* @return string 如果原字符集和目标字符集相同则返回false,否则为true
*/
function dir_iconv($in_charset, $out_charset, $dir, $fileexts = 'php|html|htm|shtml|shtm|js|txt|xml') {
if($in_charset == $out_charset) return false;
$list = dir_list($dir);
foreach($list as $v) {
if (preg_match("/.($fileexts)/i", $v) && is_file($v)){
file_put_contents($v, iconv($in_charset, $out_charset, file_get_contents($v)));
}
}
return true;
}
/**
* 列出目录下所有文件
*
* @param string $path 路径
* @param string $exts 扩展名
* @param array $list 增加的文件列表
* @return array 所有满足条件的文件
*/
function dir_list($path, $exts = '', $list= array()) {
$path = dir_path($path);
$files = glob($path.'*');
foreach($files as $v) {
$fileext = fileext($v);
if (!$exts || preg_match("/.($exts)/i", $v)) {
$list[] = $v;
if (is_dir($v)) {
$list = dir_list($v, $exts, $list);
}
}
}
return $list;
}
/**
* 设置目录下面的所有文件的访问和修改时间
*
* @param string $path 路径
* @param int $mtime 修改时间
* @param int $atime 访问时间
* @return array 不是目录时返回false,否则返回 true
*/
function dir_touch($path, $mtime = TIME, $atime = TIME) {
if (!is_dir($path)) return false;
$path = dir_path($path);
if (!is_dir($path)) touch($path, $mtime, $atime);
$files = glob($path.'*');
foreach($files as $v) {
is_dir($v) ? dir_touch($v, $mtime, $atime) : touch($v, $mtime, $atime);
}
return true;
}
/**
* 目录列表
*
* @param string $dir 路径
* @param int $parentid 父id
* @param array $dirs 传入的目录
* @return array 返回目录列表
*/
function dir_tree($dir, $parentid = 0, $dirs = array()) {
global $id;
if ($parentid == 0) $id = 0;
$list = glob($dir.'*');
foreach($list as $v) {
if (is_dir($v)) {
$id++;
$dirs[$id] = array('id'=>$id,'parentid'=>$parentid, 'name'=>basename($v), 'dir'=>$v.'/');
$dirs = dir_tree($v.'/', $id, $dirs);
}
}
return $dirs;
}
/**
* 删除目录及目录下面的所有文件
*
* @param string $dir 路径
* @return bool 如果成功则返回 TRUE,失败则返回 FALSE
*/
function dir_delete($dir) {
$dir = dir_path($dir);
if (!is_dir($dir)) return FALSE;
$list = glob($dir.'*');
foreach($list as $v) {
is_dir($v) ? dir_delete($v) : @unlink($v);
}
return @rmdir($dir);
}
?>
相关文章
- 本文给大家分享C#连接SQL数据库和查询数据功能的操作技巧,本文通过图文并茂的形式给大家介绍的非常详细,需要的朋友参考下吧...2021-05-17
- 最基础的对数据的增加删除修改操作实例,菜鸟们收了吧...2013-09-26
- 这篇文章主要介绍了解决Mybatis 大数据量的批量insert问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-01-09
Antd-vue Table组件添加Click事件,实现点击某行数据教程
这篇文章主要介绍了Antd-vue Table组件添加Click事件,实现点击某行数据教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-17- 这篇文章主要介绍了详解如何清理redis集群的所有数据,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-18
- 这篇文章主要介绍了gin 获取post请求的json body操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-15
- 新版 Mysql 中加入了对 JSON Document 的支持,可以创建 JSON 类型的字段,并有一套函数支持对JSON的查询、修改等操作,下面就实际体验一下...2016-08-23
- 这篇文章主要介绍了vue 获取到数据但却渲染不到页面上的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-11-19
- JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。JSON采用完全独立于语言的文本格式,这些特性使JSON成为理想的数据交换语言。易于人阅读和编写,同时也易于机器解析和生成...2021-11-05
- 一、常量常量是一个简单值的标识符(名字)。如同其名称所暗示的,在脚本执行期间该值不能改变(除了所谓的魔术常量,它们其实不是常量)。常量默认为大小写敏感。按照惯例常量标识符总是大写的。 常量名和其它任何 PHP 标签遵循...2015-10-30
C#使用Http Post方式传递Json数据字符串调用Web Service
这篇文章主要为大家详细介绍了C#使用Http Post方式传递Json数据字符串调用Web Service,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-25- 这篇文章主要介绍了JavaScript预解析,对象的的相关资料,小编觉得这篇文章写的还不错,需要的朋友可以参考下,希望能够给你带来帮助...2021-11-10
- 在php中解析xml文档用专门的函数domdocument来处理,把json在php中也有相关的处理函数,我们要把数据xml 数据存到一个数据再用json_encode直接换成json数据就OK了。...2016-11-25
- 这篇文章主要介绍了mybatis-plus 处理大数据插入太慢的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-18
- 下面小编就为大家带来一篇js遍历json的key和value的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2017-01-26
- 这篇文章主要介绍了postgresql数据添加两个字段联合唯一的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-04
Vue生命周期activated之返回上一页不重新请求数据操作
这篇文章主要介绍了Vue生命周期activated之返回上一页不重新请求数据操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-07-26- 这篇文章主要介绍了详解.NET Core 3.0 里新的JSON API,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-09-22
- 这篇文章主要介绍了c# socket网络编程,server端接收,client端发送数据,大家参考使用吧...2020-06-25
- 这篇文章主要介绍了解决vue watch数据的方法被调用了两次的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-07