<?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>潔靜精微 &#187; php</title>
	<atom:link href="http://julabs.me/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://julabs.me/blog</link>
	<description>想努力创造完美的东西，必须具备心灵的纯洁，同时富于宗教精神。</description>
	<lastBuildDate>Wed, 18 Jan 2012 06:34:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>PHP中的jQuery：PHP Simple HTML DOM Parser</title>
		<link>http://julabs.me/blog/php-simple-html-dom-parser/</link>
		<comments>http://julabs.me/blog/php-simple-html-dom-parser/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 15:47:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://julabs.me/blog/?p=386</guid>
		<description><![CDATA[PHP Simple HTML DOM Parser可以用类似于jQuery的语法格式来查找和修改DOM代码，非常强大易用，对于不严谨的HTML码她也能正常解析。看看下面的这些代码，是不是觉得非常像jQuery： // 创建DOM对象 $html = file_get_html('http://www.google.com/'); // 查找所有的链接，返回一个元素集合 $ret = $html-&#62;find('a'); // 返回第一个被查到的链接，如果没有找到会返回 null $ret = $html-&#62;find('a', 0); // 查找一个ID值为 foo 的元素 $ret = $html-&#62;find('#foo'); // 查找所有拥有 foo 样式名称的元素 $ret = $html-&#62;find('.foo'); // 查找所有a和img元素 $ret = &#8230; <a href="http://julabs.me/blog/php-simple-html-dom-parser/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://simplehtmldom.sourceforge.net/" target="_blank">PHP Simple HTML DOM Parser</a>可以用类似于<a href="http://jquery.com/" target="_blank">jQuery</a>的语法格式来查找和修改<abbr title="Document Object Model">DOM</abbr>代码，非常强大易用，对于不严谨的<abbr title="Hypertext Markup Language">HTML</abbr>码她也能正常解析。看看下面的这些代码，是不是觉得非常像<a href="http://jquery.com/" target="_blank">jQuery</a>：</p>
<pre><code class="php">// 创建DOM对象
$html = file_get_html('http://www.google.com/');

// 查找所有的链接，返回一个元素集合
$ret = $html-&gt;find('a');

// 返回第一个被查到的链接，如果没有找到会返回 null
$ret = $html-&gt;find('a', 0);

// 查找一个ID值为 foo 的元素
$ret = $html-&gt;find('#foo');

// 查找所有拥有 foo 样式名称的元素
$ret = $html-&gt;find('.foo');

// 查找所有a和img元素
$ret = $html-&gt;find('a,img');

// 查找所有在ul中的li
$ret = $html-&gt;find('ul li');

// 查找拥有样式名称为 hello 表格下的所有 td  元素
$es = $html-&gt;find('table.hello td');

// 查找拥有以 hello 开头的样式名称的 div 元素
$es = $html-&gt;find('div[class^="hello"]');
</code></pre>
<p>使用过<a href="http://jquery.com/" target="_blank">jQuery</a>的人应该对上面的代码风格感到非常亲切，<a href="http://simplehtmldom.sourceforge.net/" target="_blank">PHP Simple HTML DOM Parser</a>除了可以查找寻址<abbr title="Document Object Model">DOM</abbr>元素，还可以修改<abbr title="Document Object Model">DOM</abbr>，演示代码如下：</p>
<p><span id="more-386"></span></p>
<pre><code class="php">// 获得元素的 href 属性(如果属性是像 checked,selected这种类型，则返回 true 或 false)
$value = $e-&gt;href;

// 设置属性
$e-&gt;href = 'my link';

// 删除属性
$e-&gt;href = null;

// 判断元素是否拥有某种属性
if(isset($e-&gt;href))
	echo 'href exist!';
</code></pre>
<p>今人惊奇的是<a href="http://simplehtmldom.sourceforge.net/" target="_blank">PHP Simple HTML DOM Parser</a>竟然也支持类似于<a href="http://jquery.com/" target="_blank">jQuery</a>的<strong>链式</strong>功能，看下面的代码：</p>
<pre><code class="php">
echo $html-&gt;find("#div1", 0)-&gt;children(1)-&gt;children(1)-&gt;children(2)-&gt;id;
</code></pre>
<p>看了上面的演示代码，觉得<a href="http://simplehtmldom.sourceforge.net/" target="_blank">PHP Simple HTML DOM Parser</a>真是非常地强大，完整的功能演示与用法可以到她的<a href="http://simplehtmldom.sourceforge.net/" target="_blank">官方网站</a>上查找。</p>
]]></content:encoded>
			<wfw:commentRss>http://julabs.me/blog/php-simple-html-dom-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>9个需要知道的PHP函数</title>
		<link>http://julabs.me/blog/9-php-function-need-to-know/</link>
		<comments>http://julabs.me/blog/9-php-function-need-to-know/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 15:51:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://julabs.me/blog/?p=327</guid>
		<description><![CDATA[就算是使用PHP多年的老鸟，也仍然有很多不知道的函数与功能，而这些函数与功能有很多都是非常有用，而且功能强大的。要想学好PHP，我们需要不停地去参阅手册，尽可能多地了解各种函数与用法。 《9 Useful PHP Functions and Features You Need to Know》一文中就列出了9个非常实用的函数： func_get_args()：类似于JavaScript中的arguments，可以用它来获得传入函数的参数列表。 glob()：用于获得目录下的文件名称，如果想获得包括完整路径的文件名称，就要用到realpath()方法。 memory_get_usage()和memory_get_peak_usage()：获得内存使用情况。 getrusage()：获得CPU使用情况。 magic constants：魔法恒量，包括当前行数（__LINE__）、文件路径（__FILE__）、目录路径（__DIR__）、函数名称（__FUNCTION__）、类名称（__CLASS__）、方法名称（__METHOD__）以及命名空间（__NAMESPACE__）。 uniqid()：创建一个特有的字符，它创建的字符比用md5()方法创建的字符要短，可以节省些空间。 serialize()和unserialize()：一个将序列转成字符，一个将字符转成序列。如果空间支持PHP 5.2以上版本的话，可以使用json_encode()和json_decode()两个函数。 gzcompress()和gzuncompress()：一个压缩字符串，一个解压。gzencode()和gzdecode()两个函数也可以达到近似的效果，只是压缩算法不一样。 register_shutdown_function()：使用这个方法可以让你的代码在任何情况下都能执行，无论是程序出错还是用户停止执行。]]></description>
			<content:encoded><![CDATA[<p>就算是使用<strong>PHP</strong>多年的老鸟，也仍然有很多不知道的函数与功能，而这些函数与功能有很多都是非常有用，而且功能强大的。要想学好<strong>PHP</strong>，我们需要不停地去参阅手册，尽可能多地了解各种函数与用法。</p>
<p><a href="http://net.tutsplus.com/tutorials/php/9-useful-php-functions-and-features-you-need-to-know/" target="_blank">《9 Useful PHP Functions and Features You Need to Know》</a>一文中就列出了9个非常实用的函数：</p>
<ul>
<li><a href="http://us2.php.net/manual/en/function.func-get-args.php" target="_blank">func_get_args()</a>：类似于<strong>JavaScript</strong>中的<code>arguments</code>，可以用它来获得传入函数的参数列表。</li>
<li><a href="http://us.php.net/manual/en/function.glob.php" target="_blank">glob()</a>：用于获得目录下的文件名称，如果想获得包括完整路径的文件名称，就要用到<a href="http://php.net/manual/en/function.realpath.php" target="_blank">realpath()</a>方法。</li>
<li><a href="http://us2.php.net/manual/en/function.memory-get-usage.php" target="_blank">memory_get_usage()</a>和<a href="http://us2.php.net/manual/en/function.memory-get-peak-usage.php" target="_blank">memory_get_peak_usage()</a>：获得内存使用情况。</li>
<li><a href="http://us2.php.net/manual/en/function.getrusage.php" target="_blank">getrusage()</a>：获得CPU使用情况。</li>
<li><a href="http://php.net/manual/en/language.constants.predefined.php" target="_blank">magic constants</a>：魔法恒量，包括<strong>当前行数（__LINE__）</strong>、<strong>文件路径（__FILE__）</strong>、<strong>目录路径（__DIR__）</strong>、<strong>函数名称（__FUNCTION__）</strong>、<strong>类名称（__CLASS__）</strong>、<strong>方法名称（__METHOD__）</strong>以及<strong>命名空间（__NAMESPACE__）</strong>。</li>
<li><a href="http://us2.php.net/manual/en/function.uniqid.php" target="_blank">uniqid()</a>：创建一个特有的字符，它创建的字符比用<code>md5()</code>方法创建的字符要短，可以节省些空间。</li>
<li><a href="http://php.net/manual/en/function.serialize.php" target="_blank">serialize()</a>和<a href="http://www.php.net/manual/en/function.unserialize.php" target="_blank">unserialize()</a>：一个将序列转成字符，一个将字符转成序列。如果空间支持<strong>PHP 5.2</strong>以上版本的话，可以使用<a href="http://cn.php.net/manual/en/function.json-encode.php" target="_blank">json_encode()</a>和<a href="http://cn.php.net/manual/en/function.json-decode.php" target="_blank">json_decode()</a>两个函数。</li>
<li><a href="http://php.net/manual/en/function.gzcompress.php" target="_blank">gzcompress()</a>和<a href="http://www.php.net/manual/en/function.gzuncompress.php" target="_blank">gzuncompress()</a>：一个压缩字符串，一个解压。<a href="http://www.php.net/manual/en/function.gzencode.php" target="_blank">gzencode()</a>和<a href="http://www.php.net/manual/en/function.gzdecode.php" target="_blank">gzdecode()</a>两个函数也可以达到近似的效果，只是压缩算法不一样。</li>
<li><a href="http://www.php.net/manual/en/function.register-shutdown-function.php" target="_blank">register_shutdown_function()</a>：使用这个方法可以让你的代码在任何情况下都能执行，无论是程序出错还是用户停止执行。</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://julabs.me/blog/9-php-function-need-to-know/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NetTuts上的PHP操作SQLite代码</title>
		<link>http://julabs.me/blog/nettuts-php-sqlite/</link>
		<comments>http://julabs.me/blog/nettuts-php-sqlite/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 04:02:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://julabs.me/blog/?p=267</guid>
		<description><![CDATA[本来已经有了一篇《用php操作sqlite3》，但最近在NetTuts的《Creating a Web Poll with PHP》一文中发现了另一种SQLite的操作方法，虽然都是在用PDO，但是具体的步骤却不一样，方法更加兼容全面。大部分用法都和《用php操作sqlite3》基本相同，现在就列出更新和查找数据库的代码： /* 更新数据 */ try{ $dbh = new PDO('sqlite:voting.db'); $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); // 准备 $sth = $dbh->prepare("INSERT INTO tally (QID,AID,votes) values (:QID, :AID, 1)" ); // 插入新代码 $sth->execute(array('vote1',1)); $sth->execute(array('vote2',2)); }catch(PDOException $e){ // 23000错误代码表明 关键字已经存在了 &#8230; <a href="http://julabs.me/blog/nettuts-php-sqlite/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>本来已经有了一篇<a href="http://julabs.me/blog/php/php-pdo-sqlite3/" target="_blank">《用php操作sqlite3》</a>，但最近在<a href="http://www.tutsplus.com/" target="_blank">NetTuts</a>的<a href="http://net.tutsplus.com/tutorials/php/creating-a-web-poll-with-php/" target="_blank">《Creating a Web Poll with PHP》</a>一文中发现了另一种<a href="http://www.sqlite.org/" target="_blank">SQLite</a>的操作方法，虽然都是在用<strong>PDO</strong>，但是具体的步骤却不一样，方法更加兼容全面。大部分用法都和<a href="http://julabs.me/blog/php/php-pdo-sqlite3/" target="_blank">《用php操作sqlite3》</a>基本相同，现在就列出更新和查找数据库的代码：</p>
<pre><code class="php">

/* 更新数据 */
try{
	$dbh = new PDO('sqlite:voting.db');
	$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
	// 准备
	$sth = $dbh->prepare("INSERT INTO tally (QID,AID,votes) values (:QID, :AID, 1)" );
	// 插入新代码
	$sth->execute(array('vote1',1));
	$sth->execute(array('vote2',2));

}catch(PDOException $e){
	// 23000错误代码表明 关键字已经存在了
	if($e->getCode() == 23000){
		try{
			// 更新数据,并把 votes 加 1
			$sth = $dbh->prepare( "UPDATE tally SET votes = votes+1 WHERE QID=:QID AND AID=:AID");
			$sth->execute(array('vote1',1));
		}catch(PDOException $e){
			$this->db_error($e->getMessage());
		}
	}else{
		$this->db_error($e->getMessage());
	}
}

/* 获得信息 */
try{
	// 准备
	$STH = $dbh->prepare('SELECT AID, votes FROM tally WHERE QID = ?');
	// 执行查找
	$STH->execute(array('vote1'));
}catch(PDOException $e){
	// 如果发生错误,直接返回一个空值
	return array(0);
}

// 如果查找的数据不为空,逐行显示
while($row = $STH->fetch()){
	$results[$row['AID']] = $row['votes'];
	echo $row['votes'];
}

</code></pre>
<p>还有一篇<a href="http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html" target="_blank">《Introduction to PHP PDO》</a>的文章，全面介绍<strong>PDO</strong>与<a href="http://www.postgresql.org/" target="_blank">PostgreSQL</a>、<a href="http://www.sqlite.org/" target="_blank">SQLite</a>、<a href="http://www.mysql.com/" target="_blank">MySQL</a>、<a href="http://www.firebirdsql.org/" target="_blank">Firebird</a>、<a href="http://www-01.ibm.com/software/data/informix/" target="_blank">Informix</a>、<a href="http://www.oracle.com/" target="_blank">Oracle</a>、<a href="http://support.microsoft.com/kb/110093" target="_blank">ODBC</a>、<a href="http://dblib.sourceforge.net/" target="_blank">DBLIB</a>、<a href="http://www-01.ibm.com/software/data/db2/" target="_blank">IBM DB2</a>的连接，几乎包括了所有<strong>PHP</strong>能连的数据库了。</p>
]]></content:encoded>
			<wfw:commentRss>http://julabs.me/blog/nettuts-php-sqlite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用php操作sqlite3</title>
		<link>http://julabs.me/blog/php-pdo-sqlite3/</link>
		<comments>http://julabs.me/blog/php-pdo-sqlite3/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 04:09:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://julabs.me/blog/?p=240</guid>
		<description><![CDATA[Sqlite是一个跨平台的软件，不需要安装或设置，只需在最终用户的系统上创建一个数据库文件就可以了，在平台和系统之间移植非常方便。由于它具有跨平台、规模小的特点，所以被很多公司使用，如Mozilla、Adobe，Symbian等。 这段时间我也打算学习下Sqlite，做一些简单的演示时非常方便，不用在最终用户的系统安装数据库环境了。但在利用PHP操作数据库时发现PHP默认只支持到Sqlite2，不支持最新版的Sqlite3。如果想支持Sqlite3就要使用PDO。要想使用PDO，需要在php.ini里面载入php_pdo.dll和php_pdo_sqlite.dll两个模块。如下： extension=php_pdo.dll extension=php_pdo_sqlite.dll 如果这两段代码前面有;，就把它去掉。下面是我编写的Sqlite操作代码，一共有五个函数，分别是链接数据库、插入新数据、删除数据、更新数据和显示数据。 /** * 创建一个 sqlite3 链接 * @author Jon&#60;jon.ju@msn.com&#62; * @return object 返回一个数据链接对象 */ function connectSqlite(){ // 设置数据库的位置 $db = &#34;sqlite:&#34;.$_SERVER['DOCUMENT_ROOT'].&#34;/sqlite/web.db&#34;; echo $_SERVER['DOCUMENT_ROOT'].&#34;/sqlite/web.db&#34; . '&#60;br /&#62;'; $user = &#34;&#34;; $pass = &#34;&#34;; $dbHandle = new PDO($db,$user,$pass); &#8230; <a href="http://julabs.me/blog/php-pdo-sqlite3/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.sqlite.org/" target="_blank">Sqlite</a>是一个跨平台的软件，不需要安装或设置，只需在最终用户的系统上创建一个数据库文件就可以了，在平台和系统之间移植非常方便。由于它具有跨平台、规模小的特点，所以被很多公司使用，如<a href="http://www.mozilla.com/" target="_blank">Mozilla</a>、<a href="http://www.adobe.com/" target="_blank">Adobe</a>，<a href="http://www.symbian.com/" target="_blank">Symbian</a>等。</p>
<p>这段时间我也打算学习下<a href="http://www.sqlite.org/" target="_blank">Sqlite</a>，做一些简单的演示时非常方便，不用在最终用户的系统安装数据库环境了。但在利用<a href="http://php.net/" target="_blank">PHP</a>操作数据库时发现<a href="http://php.net/" target="_blank">PHP</a>默认只支持到<strong>Sqlite2</strong>，不支持最新版的<strong>Sqlite3</strong>。如果想支持<strong>Sqlite3</strong>就要使用<strong>PDO</strong>。要想使用<strong>PDO</strong>，需要在<strong>php.ini</strong>里面载入<strong>php_pdo.dll</strong>和<strong>php_pdo_sqlite.dll</strong>两个模块。如下：</p>
<pre><code class="apache">extension=php_pdo.dll
extension=php_pdo_sqlite.dll
</code></pre>
<p>如果这两段代码前面有<strong>;</strong>，就把它去掉。下面是我编写的<a href="http://www.sqlite.org/" target="_blank">Sqlite</a>操作代码，一共有五个函数，分别是链接数据库、插入新数据、删除数据、更新数据和显示数据。</p>
<pre><code class="php">
/**
 * 创建一个 sqlite3 链接
 * @author Jon&lt;jon.ju@msn.com&gt;
 * @return object 返回一个数据链接对象
*/
function connectSqlite(){
    // 设置数据库的位置
    $db = &quot;sqlite:&quot;.$_SERVER['DOCUMENT_ROOT'].&quot;/sqlite/web.db&quot;;
    echo $_SERVER['DOCUMENT_ROOT'].&quot;/sqlite/web.db&quot; . '&lt;br /&gt;';
    $user = &quot;&quot;;
    $pass = &quot;&quot;;
    $dbHandle = new PDO($db,$user,$pass);
    echo 'Connected to database&lt;br /&gt;';
    return $dbHandle;
}
/**
 * 插入新数据
*/
function insertSqlite($conn){
    $qry = $conn-&gt;query('select * from site');
    //如果不存在，则创建表
    if($qry ==false){
    $conn-&gt;exec('create table mysite(name VARCHAR(30),url VARCHAR(50))');
    }
    // 准备存入数据
    $insert = $conn-&gt;prepare(&quot;INSERT into mysite VALUES(?,?)&quot;);
    // 存入数据
    $insert-&gt;execute(array('julabs','julabe.com'));
    $insert-&gt;execute(array('google','www.google.com'));
}
/**
 * 删除数据
*/
function deleteSqlite($conn){
	$conn-&gt;exec(&quot;DELETE FROM mysite WHERE name = 'google'&quot;);
}

/**
 * 更新数据
*/
function updateSqlite($conn){
	$conn-&gt;exec(&quot;UPDATE mysite set url='julabs.me' WHERE name = 'julabs'&quot;);
}

/**
 * 显示数据
*/
function showSqlite($conn){
    $sth = $conn-&gt;prepare(&quot;SELECT * FROM mysite&quot;);
    $sth-&gt;execute();
    $result = $sth-&gt;fetchAll(PDO::FETCH_ASSOC);
    echo '&lt;br /&gt;共有&lt;strong&gt;' . count($result) . '&lt;/strong&gt;条数据&lt;br /&gt;';
    echo '&lt;table&gt;';
    echo '&lt;tr&gt;&lt;th&gt;名称&lt;/th&gt;&lt;th&gt;地址&lt;/th&gt;&lt;/tr&gt;';
    foreach($result as $row){
        echo '&lt;tr&gt;';
        foreach($row as $key =&gt; $val){
            echo '&lt;td&gt;';
            echo $val;
            echo '&lt;/td&gt;';
        }
    	echo '&lt;/tr&gt;';
    }
    echo '&lt;/table&gt;';
}

$connect = connectSqlite();
insertSqlite($connect);
showSqlite($connect);
updateSqlite($connect);
showSqlite($connect);
deleteSqlite($connect);
showSqlite($connect);
$connect = NULL;
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://julabs.me/blog/php-pdo-sqlite3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>常用时区与语言编码</title>
		<link>http://julabs.me/blog/time-zone-and-language-code/</link>
		<comments>http://julabs.me/blog/time-zone-and-language-code/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 09:35:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[zone]]></category>

		<guid isPermaLink="false">http://julabs.me/blog/?p=223</guid>
		<description><![CDATA[在编程时，有时候会遇到时区和语言编码配置问题。在中国所用的时区码一般为下面几个： Asia/Shanghai；大陆东部，包括北京、上海、广州等； Asia/Harbin；大陆东北，包括黑龙江、吉林等，但不包括漠河； Asia/Chongqing；大陆中部，包括四川、云南、广西、陕西、贵州等； Asia/Hong_Kong；香港； Asia/Taipei；台北； 更详细的时区码内容请参见List of tz database time zones，但为什么没有Asia/Beijing这样的设置呢？ 在中国所用到的语言编码一般有下面几个： zh-tw；中文繁体（台湾）； zh-cn；中文简体； zh-hk；中文繁体（香港）； zh-sg；新加坡中文； 更详细的语言编码内容请参见Language Codes。]]></description>
			<content:encoded><![CDATA[<p>在编程时，有时候会遇到时区和语言编码配置问题。在中国所用的时区码一般为下面几个：</p>
<ul>
<li>Asia/Shanghai；大陆东部，包括北京、上海、广州等；</li>
<li>Asia/Harbin；大陆东北，包括黑龙江、吉林等，但不包括漠河；</li>
<li>Asia/Chongqing；大陆中部，包括四川、云南、广西、陕西、贵州等；</li>
<li>Asia/Hong_Kong；香港；</li>
<li>Asia/Taipei；台北；</li>
</ul>
<p>更详细的时区码内容请参见<a href="http://en.wikipedia.org/wiki/List_of_tz_zones_by_name" target="_blank">List of tz database time zones</a>，但为什么没有<strong>Asia/Beijing</strong>这样的设置呢？</p>
<p>在中国所用到的语言编码一般有下面几个：</p>
<ul>
<li>zh-tw；中文繁体（台湾）；</li>
<li>zh-cn；中文简体；</li>
<li>zh-hk；中文繁体（香港）；</li>
<li>zh-sg；新加坡中文；</li>
</ul>
<p>更详细的语言编码内容请参见<a href="http://msdn.microsoft.com/en-us/library/ms533052(VS.85).aspx" target="_blank">Language Codes</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://julabs.me/blog/time-zone-and-language-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用PHP侦测浏览器名称版本</title>
		<link>http://julabs.me/blog/php-browser-check/</link>
		<comments>http://julabs.me/blog/php-browser-check/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 10:22:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[浏览器]]></category>

		<guid isPermaLink="false">http://julabs.me/blog/?p=122</guid>
		<description><![CDATA[现在的浏览器有很多种，每种又有不同的版本，为了让网页在不同的浏览器的呈现出相同的样式，页面制做人员便使用大量的偏方（即hack，我把它叫做偏方）。做这种事情是很痛苦的，做过的人都知道。于是有些人分别针对不同的浏览器编写相对应的CSS文件，然后用IE条件注释方式来判断载入，代码如下： &#60;link href=&#34;common.css&#34; type=&#34;text/css&#34; media=&#34;screen, projection&#34; /&#62; &#60;!--[if IE 7]&#62;&#60;link href=&#34;ie7.css&#34; type=&#34;text/css&#34; media=&#34;screen, projection&#34; /&#62; &#60;![endif]--&#62;&#60;!--[if IE 6]&#62;&#60;link href=&#34;ie6.css&#34; type=&#34;text/css&#34; media=&#34;screen, projection&#34; /&#62; &#60;![endif]--&#62; 其实也可以用后台动态语言来判断浏览器种类的。在PHP中可以使用函数&#8220;$_SERVER['HTTP_USER_AGENT']&#8221;，它和JS中的&#8220;navigator.userAgent&#8221;函数具有相似的功能，而且我在PHP官网上找到一篇介绍介绍get_browser函数的文章，在里面找到了不少判断浏览器种类的代码，现转一个在这里： &#60;?php // _______ // ----- &#124; CONF. &#124; // add new browsers in lower case &#8230; <a href="http://julabs.me/blog/php-browser-check/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>现在的浏览器有很多种，每种又有不同的版本，为了让网页在不同的浏览器的呈现出相同的样式，页面制做人员便使用大量的偏方（即hack，我把它叫做偏方）。做这种事情是很痛苦的，做过的人都知道。于是有些人分别针对不同的浏览器编写相对应的CSS文件，然后用IE条件注释方式来判断载入，代码如下：</p>
<pre><code class="html">&lt;link href=&quot;common.css&quot; type=&quot;text/css&quot; media=&quot;screen, projection&quot; /&gt;
&lt;!--[if IE 7]&gt;&lt;link href=&quot;ie7.css&quot; type=&quot;text/css&quot; media=&quot;screen, projection&quot; /&gt;
&lt;![endif]--&gt;&lt;!--[if IE 6]&gt;&lt;link href=&quot;ie6.css&quot; type=&quot;text/css&quot; media=&quot;screen, projection&quot; /&gt;
&lt;![endif]--&gt;</code></pre>
<p>其实也可以用后台动态语言来判断浏览器种类的。在PHP中可以使用函数&ldquo;$_SERVER['HTTP_USER_AGENT']&rdquo;，它和JS中的&ldquo;navigator.userAgent&rdquo;函数具有相似的功能，而且我在<a href="http://www.php.net/" class="blank">PHP官网</a>上找到一篇<a href="http://us2.php.net/manual/en/function.get-browser.php" class="blank">介绍介绍get_browser函数的文章</a>，在里面找到了不少判断浏览器种类的代码，现转一个在这里：</p>
<pre><code class="php">&lt;?php
//        _______
// ----- &#124; CONF. &#124;
// add new browsers in lower case here, separated
// by spaces -  order is important: from left to
// right browser family becomes more precise$browsers = &quot;mozilla msie gecko firefox &quot;;
$browsers.= &quot;konqueror safari netscape navigator &quot;;
$browsers.= &quot;opera mosaic lynx amaya omniweb&quot;;
//        _______
// ----- &#124;PROCESS&#124;
$browsers = split(&quot; &quot;, $browsers);
$nua = strToLower( $_SERVER['HTTP_USER_AGENT']);
$l = strlen($nua);
for ($i=0; $i&lt;count($browsers); $i++){
	$browser = $browsers[$i];
	$n = stristr($nua, $browser);
	if(strlen($n)&gt;0){
		$GLOBALS[&quot;ver&quot;] = &quot;&quot;;
		$GLOBALS[&quot;nav&quot;] = $browser;
		$j=strpos($nua, $GLOBALS[&quot;nav&quot;])+$n+strlen($GLOBALS[&quot;nav&quot;])+1;
		for (; $j&lt;=$l; $j++){
			$s = substr ($nua, $j, 1);
			if(is_numeric($GLOBALS[&quot;ver&quot;].$s) )
			$GLOBALS[&quot;ver&quot;] .= $s;
			else
			break;
		}
	}
}
//        _______

// ----- &#124;  USE  &#124;

echo(&quot;&lt;pre&gt;Your browser is: &quot;);
echo($GLOBALS[&quot;nav&quot;] . &quot; &quot; . $GLOBALS[&quot;ver&quot;] . &quot;&lt;/pre&gt;&quot;);
?&gt;
</code></pre>
<p>如果你用的是IE6，页面会显示：Your browser is: msie 6.0；如果用的是火狐2，会显示：Your browser is: firefox 2.0。</p>
]]></content:encoded>
			<wfw:commentRss>http://julabs.me/blog/php-browser-check/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>与JS的encodeURIComponent相对应的PHP函数</title>
		<link>http://julabs.me/blog/js-php-encode/</link>
		<comments>http://julabs.me/blog/js-php-encode/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 08:22:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[encode]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://julabs.me/blog/?p=48</guid>
		<description><![CDATA[在用AJAX与后台交互时经常要对中文进行编码解码，对于JS来说有两个函数：encodeURIComponent用于编码，decodeURIComponent用于解码。而对于后台的PHP来说有两个相对应的编码解码函数：urlencode用于编码，urldecode用于解码。现在看下列两段代码，先给个PHP代码： &#60;?php $myStr1 = '我是中国人'; $myStr2 = urlencode($myStr1); echo $myStr1 . '&#60;br /&#62;'; echo $myStr2 . '&#60;br /&#62;'; echo urldecode($myStr2) . '&#60;br /&#62;'; ?&#62; 上面这段php代码会输出: 我是中国人 %E6%88%91%E6%98%AF%E4%B8%AD%E5%9B%BD%E4%BA%BA 我是中国人 再来看JS代码： var myStr1 = '我是中国人'; var myStr2 = encodeURIComponent(myStr1); document.write(myStr1);document.write('&#60;br /&#62;'); document.write(myStr2);document.write('&#60;br &#8230; <a href="http://julabs.me/blog/js-php-encode/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>在用AJAX与后台交互时经常要对中文进行编码解码，对于JS来说有两个函数：encodeURIComponent用于编码，decodeURIComponent用于解码。而对于后台的PHP来说有两个相对应的编码解码函数：urlencode用于编码，urldecode用于解码。现在看下列两段代码，先给个PHP代码：</p>
<pre><code class="php">&lt;?php
$myStr1 = '我是中国人';
$myStr2 = urlencode($myStr1);
echo $myStr1 . '&lt;br /&gt;';
echo $myStr2 . '&lt;br /&gt;';
echo urldecode($myStr2) . '&lt;br /&gt;';
?&gt;
</code></pre>
<p>上面这段php代码会输出:</p>
<pre><code>我是中国人
%E6%88%91%E6%98%AF%E4%B8%AD%E5%9B%BD%E4%BA%BA
我是中国人</code></pre>
<p>再来看JS代码：</p>
<pre><code class="javascript">var myStr1 = '我是中国人';
var myStr2 = encodeURIComponent(myStr1);
document.write(myStr1);document.write('&lt;br /&gt;');
document.write(myStr2);document.write('&lt;br /&gt;');
document.write(decodeURIComponent(myStr2));
</code></pre>
<p>上面这段JS代码会输出:</p>
<pre><code>我是中国人
%E6%88%91%E6%98%AF%E4%B8%AD%E5%9B%BD%E4%BA%BA
我是中国人
</code></pre>
<p>和上面PHP代码输出的内容是一样的。</p>
]]></content:encoded>
			<wfw:commentRss>http://julabs.me/blog/js-php-encode/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AMFPHP 1.9的中文问题</title>
		<link>http://julabs.me/blog/amfphp-chinese/</link>
		<comments>http://julabs.me/blog/amfphp-chinese/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 07:24:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[amf]]></category>

		<guid isPermaLink="false">http://julabs.me/blog/?p=9</guid>
		<description><![CDATA[AMFPHP 1.9里直接使用中文会在传递数据时发生乱码，这个问题在AMFPHP中的gateway.php文件就已经给出了解决方法。 见gateway.php文件中的注释： // Oriental languages (Chinese, japanese, korean): $gateway->setCharsetHandler( "none", "ISO-8859-1", "ISO-8859-1" ); $gateway->setCharsetHandler( "iconv", "big5", "big5" ); $gateway->setCharsetHandler( "iconv", "CP950", "CP950" ); $gateway->setCharsetHandler( "iconv", "Shift_JIS", "Shift_JIS" ); $gateway->setCharsetHandler( "iconv", "CP932", "CP932" ); $gateway->setCharsetHandler( "iconv", "CP949", "CP949" ); 也就是说你的文件是用什么格式编码的，就把gateway.php文件中的$gateway->setCharsetHandler( &#8230; <a href="http://julabs.me/blog/amfphp-chinese/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>AMFPHP 1.9里直接使用中文会在传递数据时发生乱码，这个问题在AMFPHP中的gateway.php文件就已经给出了解决方法。</p>
<p>见gateway.php文件中的注释：</p>
<pre><code class="php">// Oriental languages (Chinese, japanese, korean):
$gateway->setCharsetHandler( "none", "ISO-8859-1", "ISO-8859-1" );
$gateway->setCharsetHandler( "iconv", "big5", "big5" );
$gateway->setCharsetHandler( "iconv", "CP950", "CP950" );
$gateway->setCharsetHandler( "iconv", "Shift_JIS", "Shift_JIS" );
$gateway->setCharsetHandler( "iconv", "CP932", "CP932" );
$gateway->setCharsetHandler( "iconv", "CP949", "CP949" );
</code></pre>
<p>也就是说你的文件是用什么格式编码的，就把gateway.php文件中的<code>$gateway->setCharsetHandler( "iconv", "big5", "big5" );</code>中的两个“big5”改成相对应的编码名称就可以了。而在中国，一般使用“utf-8”、“gb2312”和“big5”，我用“utf-8”，所以在gateway.php文件中找到<code>$gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");</code>一行代码，把它改成<code>$gateway->setCharsetHandler("iconv", "UTF-8", "UTF-8");</code>就能正常传递中文数据了！</p>
]]></content:encoded>
			<wfw:commentRss>http://julabs.me/blog/amfphp-chinese/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

