<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>运达&#039;s  blog &#187; Json</title>
	<atom:link href="https://www.yunda51.com/?cat=108&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>https://www.yunda51.com</link>
	<description>运达的博客</description>
	<lastBuildDate>Wed, 12 Nov 2025 07:58:26 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.19</generator>
	<item>
		<title>php如何生成缓存文件（生成，获取，删除）</title>
		<link>https://www.yunda51.com/?p=1653</link>
		<comments>https://www.yunda51.com/?p=1653#comments</comments>
		<pubDate>Wed, 16 Dec 2015 08:46:41 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Json]]></category>
		<category><![CDATA[php技术]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[缓存]]></category>
		<category><![CDATA[缓存文件]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1653</guid>
		<description><![CDATA[闲着无聊写着玩，最主要原因是博客好久没更新内容，也就是凑合更新点内容，哈哈！言归正传 代码如下： &#60;?p<a href="https://www.yunda51.com/?p=1653" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>闲着无聊写着玩，最主要原因是博客好久没更新内容，也就是凑合更新点内容，哈哈！言归正传<br />
<strong>代码如下：</strong></p>
<pre class="wp-code-highlight prettyprint">
&lt;?php
	error_reporting(0);
	header(&quot;Content-Type:text/html; charset=UTF-8&quot;);
	class File{
		private $_dir;
		const suffix=&#039;.txt&#039;;
		public function __construct(){
			//默认的缓存文件存放路径
			$this-&gt;_dir=dirname(__FILE__).&#039;/cache/&#039;;
		}

		/**
		**缓存文件的写入，获取，删除!
		**@params  $key     缓存文件的文件名
		**@params  $value   缓存数据
		**@params  $path    路径
		**/
		public function cacheDate($key,$value=&#039;&#039;,$path=&#039;&#039;){
			//拼装成一个文件
			$filename=$this-&gt;_dir.$path.$key.self::suffix;
			if($value!==&#039;&#039;){//将value值写入缓存
				//如果值为null的时候，就删除文件
				if(is_null($value)){
					return unlink($filename);
				}
				//获取目录
				$dir = dirname($filename);
				//判断目录是否存在，不存在就创建目录
				if(!is_dir($dir)){
					mkdir($dir,0777);
				}
				return file_put_contents($filename,json_encode($value));
			}

			//判断文件是否存在
			if(!is_file($filename)){
				return false;
			}else{
				//获取缓存文件里的数据
				return json_decode(file_get_contents($filename),true);
			}
		}
	}

    $data = array(&#039;id&#039;=&gt;1,&#039;name&#039;=&gt;&#039;运达blog&#039;,&#039;age&#039;=&gt;25,&#039;like&#039;=&gt;&#039;游泳，旅游&#039;);
    $list = new File();
     
    //获取缓存文件数据
    if($list-&gt;cacheDate(&#039;cache_file&#039;)==null){
    	echo &quot;缓存文件不存在或者缓存数据为空！&quot;.&#039;&lt;br/&gt;&#039;;
    }else{
    	var_dump($list-&gt;cacheDate(&#039;cache_file&#039;));
    }

    //生成缓存文件
    if($list-&gt;cacheDate(&#039;cache_file&#039;,$data)){
    	echo &quot;数据缓存成功！&quot;;
    }else{
    	echo &quot;数据缓存失败！&quot;;
    }

    //数据为null的时候，删除缓存文件
    if($list-&gt;cacheDate(&#039;cache_file&#039;,null)){
    	echo &quot;删除缓存文件成功！&quot;;
    }else{
    	echo &quot;删除缓存文件失败！&quot;;
    }

?&gt;
</pre>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1653.html">http://www.yunda51.com/1653.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1653</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>打印json的错误级别json_last_error</title>
		<link>https://www.yunda51.com/?p=1527</link>
		<comments>https://www.yunda51.com/?p=1527#comments</comments>
		<pubDate>Wed, 22 Apr 2015 10:24:18 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Json]]></category>
		<category><![CDATA[php技术]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[json_last_error]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1527</guid>
		<description><![CDATA[json_last_error — 返回最后发生的错误 说明： int json_last_error ( v<a href="https://www.yunda51.com/?p=1527" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>json_last_error — 返回最后发生的错误<br />
<strong>说明：</strong> int json_last_error ( void )<br />
如果有，返回 JSON 编码解码时最后发生的错误。 </p>
<pre class="wp-code-highlight prettyprint">
0 JSON_ERROR_NONE 	No error has occurred   没有错误发生 	
 
1 JSON_ERROR_DEPTH 	The maximum stack depth has been exceeded  	
 
2 JSON_ERROR_STATE_MISMATCH 	Invalid or malformed JSON  无效或不正确的JSON 	
 
3 JSON_ERROR_CTRL_CHAR 	Control character error, possibly incorrectly encoded 控制字符的错误，可能是错误编码

4 JSON_ERROR_SYNTAX 	Syntax error  语法错误 	 

5 JSON_ERROR_UTF8 	Malformed UTF-8 characters, possibly incorrectly encoded 畸形的UTF-8字符，可能错误编码
</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1527</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
