<?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://ringtail.xmulib.org/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://ringtail.xmulib.org</link>
	<description>爱睡懒觉的小熊</description>
	<lastBuildDate>Sun, 04 Jul 2010 03:00:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>使用php的tidy解析html</title>
		<link>http://ringtail.xmulib.org/2009/12/03/shiyongphpdetidyjiexihtml/</link>
		<comments>http://ringtail.xmulib.org/2009/12/03/shiyongphpdetidyjiexihtml/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 03:27:59 +0000</pubDate>
		<dc:creator>ringtail</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[html parser]]></category>

		<guid isPermaLink="false">http://ringtail.xmulib.org/?p=108</guid>
		<description><![CDATA[php tidy html parse]]></description>
			<content:encoded><![CDATA[<p>以前解析html都是使用正则表达式，但是用起来比较麻烦。现在开始使用php的tidy库。</p>
<p>示例如下： 摘自：<a href="http://us3.php.net/tidy.root" target="_blank">http://us3.php.net/tidy.root</a></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt; HTML
&nbsp;
paragraph
&nbsp;
HTML</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$tidy</span> <span style="color: #339933;">=</span> <span style="color: #990000;">tidy_parse_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
dump_nodes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tidy</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">root</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> dump_nodes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">,</span> <span style="color: #000088;">$indent</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasChildren</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">child</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$child</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$indent</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> ? <span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
            dump_nodes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #339933;">,</span> <span style="color: #000088;">$indent</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>要注意的一点是，对于GBK编码的HTML需要先转换编码为UTF8的，然后使用</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$tidy</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> tidy<span style="color: #339933;">;</span>
<span style="color: #000088;">$tidy</span> <span style="color: #339933;">-&gt;</span><span style="color: #004000;">parseString</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>来解析。</p>
<p>====后续分割线===</p>
<p>最近又使用一种新的方法来解析html，当然还是用php。</p>
<p>使用一个叫做PHP Simple HTML DOM Parser的类。感谢某同学的帮助。</p>
<p>英文链接地址：<a href="http://simplehtmldom.sourceforge.net/" target="_blank">http://simplehtmldom.sourceforge.net/</a></p>
<p>中文链接地址：<a href="http://phpdom.comsing.com/" target="_blank">http://phpdom.comsing.com/</a></p>
<p>这个类使用起来非常方便，单就解析html这一点来说，比tidy好用。而且文档齐全，简单易懂。</p>
<p>示例如下：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">                <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> simple_html_dom<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$img</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'img'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">href</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">src</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
							<span style="color: #0000ff;">'href'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$a</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">href</span><span style="color: #339933;">,</span>
							<span style="color: #0000ff;">'src'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$img</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">src</span><span style="color: #339933;">,</span>
				<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ringtail.xmulib.org/2009/12/03/shiyongphpdetidyjiexihtml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpDocumentor学习笔记</title>
		<link>http://ringtail.xmulib.org/2008/09/12/phpdocumentor%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/</link>
		<comments>http://ringtail.xmulib.org/2008/09/12/phpdocumentor%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 03:11:48 +0000</pubDate>
		<dc:creator>ringtail</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[笔记]]></category>

		<guid isPermaLink="false">http://ringtail.xmulib.org/2008/09/12/phpdocumentor%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/</guid>
		<description><![CDATA[前言：
使用phpDocumentor的好处：
你喜歡寫文件嗎？我不喜歡。尤其是在趕工的時候，哪來的美國時間寫文件；就算有時間也是希望趕快把事情做完閃人，怎樣都輪不到寫文件的時候。
文件需要嗎？雖然不喜歡寫文件，但文件真的是必要的。對自己而言，正當在趕案子兵荒馬亂的時候，突然要某個以前寫過的函式結果不知道放哪去了，這時心情會很糟很糟的去把以前的碼挖出來一份一份看，才能找出所要的函式，這樣更浪費時間。對於他人而言，要是每個人寫出來的東西都可以再讓其它人了解，並且進一步使用其它人早已寫好的元件，可以讓我們再省下時間來多喝幾杯咖啡。
那要怎麼樣讓編寫文件輕鬆又自在？ phpDocumentor 就是一個現成好用的工具，只要在寫程式時順手寫上一點點的註解，困難一點的可以再加上一點點的範例。寫完後交給 phpDocumentor 編譯，一下子圖文並茂的程式文件自動就產生了。而且它還不只可以產生 HTML 檔，還可以產生出 PDF, CHM 等文件。就算產生 HTML 檔，還有許多的風格可以選擇。這樣好用的工具放著不用，實在太可惜了。
這份資料裡，只會出現馬上能用的資料，除了這個簡介外，不會廢話太多，所以文件中的文句也冰冷了些。會這樣做的目的是希望文件的每一個部份都能讓讀者快速吸收，任何一個例子複製下來後馬上能用。文件中的每個樣版我都是精心設計過，起碼我以後要用的時候不必再想說要寫一個類別正常需要哪些 Tag ，只要把樣版複製下來以後就直接可以用了。
由於此文件中資料只有使用上最需要的部份（也是一定能用的部份），因此若在使用上想要了解更多，可以到 phpDocumentor 的官方網站 (http://www.phpdoc.org/)上找到所需資料。
——————摘自 《phpDocumentor筆記 0 立即體驗》
http://pkwbim-programming-note.blogspot.com/2008/01/phpdocumentor-0.html#0.4
其实这篇文章已经写的比较简要，但是为了防止哪天这个网站被盾了，我还是抄到自己的blog比较安全。
简而言之，phpDocumentor就适合我这样写过代码就忘了的人，规范的书写注释还能生成文档，多省事。
1.安装
1.1如果没有安装过pear，可以先运行PHP目录下的go-pear.bat安装。
1.2安装过pear之后，使用下面的命令安装phpDocumentor：
\php5\PEAR\pear install -o PhpDocumentor
2.字符编码的问题
看到很多人都说需要改字符编码，但是我下载的phpDocumentor v1.4.2 没有遇到这个问题，也没有
查找到&#8221;iso-8859-1&#8243;这个字符串。
3.生成文件
步驟
3.1 将範例碼存成 example.php 置於 \project\php_project\下。
3.2 在命令列下用以下指令
phpdoc &#8211;parseprivate -o HTML:frames:earthli -f \project\php_project\example.php -t \project\php_project\docs
或
phpdoc &#8211;parseprivate -o HTML:Smarty:PHP -d \project\php_project\ -t \project\php_project\docs
3.3 解說
* &#8211;parseprivate： 是將私有 (private) 成員函式或私有變數等等也都加入程式文件裡。沒有這參數的話，產生出的文件裡只會有公開的 (public) 和受保護的 (protected) 的成員函式和變數。
* -f ： [...]]]></description>
			<content:encoded><![CDATA[<p>前言：<br />
使用phpDocumentor的好处：<br />
你喜歡寫文件嗎？我不喜歡。尤其是在趕工的時候，哪來的美國時間寫文件；就算有時間也是希望趕快把事情做完閃人，怎樣都輪不到寫文件的時候。</p>
<p>文件需要嗎？雖然不喜歡寫文件，但文件真的是必要的。對自己而言，正當在趕案子兵荒馬亂的時候，突然要某個以前寫過的函式結果不知道放哪去了，這時心情會很糟很糟的去把以前的碼挖出來一份一份看，才能找出所要的函式，這樣更浪費時間。對於他人而言，要是每個人寫出來的東西都可以再讓其它人了解，並且進一步使用其它人早已寫好的元件，可以讓我們再省下時間來多喝幾杯咖啡。</p>
<p>那要怎麼樣讓編寫文件輕鬆又自在？ phpDocumentor 就是一個現成好用的工具，只要在寫程式時順手寫上一點點的註解，困難一點的可以再加上一點點的範例。寫完後交給 phpDocumentor 編譯，一下子圖文並茂的程式文件自動就產生了。而且它還不只可以產生 HTML 檔，還可以產生出 PDF, CHM 等文件。就算產生 HTML 檔，還有許多的風格可以選擇。這樣好用的工具放著不用，實在太可惜了。</p>
<p>這份資料裡，只會出現馬上能用的資料，除了這個簡介外，不會廢話太多，所以文件中的文句也冰冷了些。會這樣做的目的是希望文件的每一個部份都能讓讀者快速吸收，任何一個例子複製下來後馬上能用。文件中的每個樣版我都是精心設計過，起碼我以後要用的時候不必再想說要寫一個類別正常需要哪些 Tag ，只要把樣版複製下來以後就直接可以用了。</p>
<p>由於此文件中資料只有使用上最需要的部份（也是一定能用的部份），因此若在使用上想要了解更多，可以到 <a href="http://www.phpdoc.org/">phpDocumentor 的官方網站 (http://www.phpdoc.org/)</a>上找到所需資料。<br />
——————摘自 <a href="http://pkwbim-programming-note.blogspot.com/2008/01/phpdocumentor-0.html#0.4">《phpDocumentor筆記 0 立即體驗》</a><br />
<a href="http://pkwbim-programming-note.blogspot.com/2008/01/phpdocumentor-0.html#0.4">http://pkwbim-programming-note.blogspot.com/2008/01/phpdocumentor-0.html#0.4</a></p>
<p>其实这篇文章已经写的比较简要，但是为了防止哪天这个网站被盾了，我还是抄到自己的blog比较安全。<br />
简而言之，phpDocumentor就适合我这样写过代码就忘了的人，规范的书写注释还能生成文档，多省事。</p>
<p>1.安装<br />
1.1如果没有安装过pear，可以先运行PHP目录下的go-pear.bat安装。<br />
1.2安装过pear之后，使用下面的命令安装phpDocumentor：<br />
\php5\PEAR\pear install -o PhpDocumentor</p>
<p>2.字符编码的问题<br />
看到很多人都说需要改字符编码，但是我下载的phpDocumentor v1.4.2 没有遇到这个问题，也没有<br />
查找到&#8221;iso-8859-1&#8243;这个字符串。</p>
<p>3.生成文件<br />
步驟</p>
<p>3.1 将範例碼存成 example.php 置於 \project\php_project\下。<br />
3.2 在命令列下用以下指令</p>
<p>phpdoc &#8211;parseprivate -o HTML:frames:earthli -f \project\php_project\example.php -t \project\php_project\docs</p>
<p>或</p>
<p>phpdoc &#8211;parseprivate -o HTML:Smarty:PHP -d \project\php_project\ -t \project\php_project\docs</p>
<p>3.3 解說<br />
* &#8211;parseprivate： 是將私有 (private) 成員函式或私有變數等等也都加入程式文件裡。沒有這參數的話，產生出的文件裡只會有公開的 (public) 和受保護的 (protected) 的成員函式和變數。<br />
* -f ： 是指針對某個檔案產生註解文件。<br />
* -d ： 針對某個目錄（含其子目錄）產生註解文件。<br />
* -t ： 指定要輸出的目錄<br />
* -o ： 指定輸出格式，上例的格式有兩種<br />
o HTML:frames:earthli ： 是輸出有一種帶有框架 (frame) 的說明文件，所產生出來的文件非常漂亮。Zend Framework 的 API 文件就是採用這種風格。<br />
o HTML:Smarty:PHP ： 產生的文件看起來就像是 PHP 網站上或是 phpDocumentor 官網上的的一樣。</p>
<p>待程式結束後，瀏覽剛剛指定產生文件的目錄下，會有一個 index.html 檔，以瀏覽器打開它就可以看到 phpDocumentor 產生出來的程式文件。倘若在產生文件的過程中，有任何的錯誤，這些錯誤會出現在 error.html檔裡。</p>
<p>4.范例</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #009933; font-style: italic;">/**
* phpDocumentor 使用示範
* 這個檔案是一個簡單的示範
* 內容涵蓋了許多常用的註解方式。
* 有任何的問題請和作者連絡
* @package phpDocumentorExample
* @author 多采多姿 &amp;lt;pkwbim.programming@gmail.com&amp;gt;
* @version 0.1b
*/</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
* 這是 lib.inc.php 的標題
* 這是 lib.inc.php 的描述
*/</span>
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lib.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
* 圓周率
* 圓周和直徑的比值
*/</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pi'</span><span style="color: #339933;">,</span> <span style="color:#800080;">3.14159</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
*  這是 funtion1 的註解區塊標題
*  這是 funtion1 的描述
*  @global int 這是函式內第一個全域變數的註解，就是 $global1 的註解
*  @global string 這是函式內第二個全域變數的註解，就是 $global2 的註解
*  @param bool $arg1 這是函式參數 $arg1 的註解
*  @param int|string $arg2 這裡是函式參數 $arg2 的註解
*  @return mixed 傳回值的註解
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> function1<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arg1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arg2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$global1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$global2</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arg1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arg2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
* 這是MyClass的標題
*
* 建立簡寫型的清單
* 這裡建立一份無序清單
* - 項目一
* - 項目二，
*   每個項目可以是多行，
*   就像這個項目，
*   這行還在項目二中
* - 項目三
* 清單結束，因為沒縮排
* 這裡建立一份有序清單
* 1 有序的項目一，數字後一定要加一個空白。
* 2 有序的項目二
* 有序清單的另一種寫法
* 1. ordered item 1
* 2. ordered item 2
* 清單在此結束
*
* @package phpDocumentorExample
* @author 多采多姿
* @since 1.0rc1
* @version 0.2b
*
*/</span>
<span style="color: #000000; font-weight: bold;">class</span> MyClass <span style="color: #009900;">&#123;</span>
<span style="color: #009933; font-style: italic;">/**
* 這裡是成員變數的註解
*
* @var string 成員變數的註解
* @access private
*/</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_variable</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hello&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
* 這是一個公開的成員函式
*
* @param bool $var1 參數1
* @param string|array $var2 參數1
* @return void
* @access public
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> set_vars<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>要注意所有的注释都是有两个星号的C-style注释，如下所示</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
*
*/</span></pre></div></div>

<p>语法参考文档： <a href="http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.quickstart.pkg.html#coding">http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.quickstart.pkg.html#coding</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ringtail.xmulib.org/2008/09/12/phpdocumentor%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>字符串编码转换小结2</title>
		<link>http://ringtail.xmulib.org/2008/05/07/%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e5%b0%8f%e7%bb%932/</link>
		<comments>http://ringtail.xmulib.org/2008/05/07/%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e5%b0%8f%e7%bb%932/#comments</comments>
		<pubDate>Wed, 07 May 2008 03:16:55 +0000</pubDate>
		<dc:creator>ringtail</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[other]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[字符编码]]></category>

		<guid isPermaLink="false">http://ringtail.xmulib.org/2008/05/07/%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e5%b0%8f%e7%bb%932/</guid>
		<description><![CDATA[&#160;今天早上，网页忽然正常显示了，原来是修改了注册表的原因。&#160;在数据库迁移后(sql server :gbk2312 到 Oracle : UTF8)，可能出现页面字符乱码的原因：
1.oracle字符集设置不正确。
数据库服务器字符集select * from nls_database_parameters，其来源于props$，是表示数据库的字符集。客户端字符集环境select * from nls_instance_parameters,其来源于v$parameter，表示客户端的字符集的设置。可能是参数文件，环境变量或者是注册表会话字符集环境select * from nls_session_parameters，其来源于v$nls_parameters，表示会话自己的设置，可能是会话的环境变量或者是alter session完成，如果会话没有特殊的设置，将与nls_instance_parameters一致。

客户端的字符集要求与服务器一致，才能正确显示数据库的非Ascii字符。如果多个设置存在的时候，alter session&#62;环境变量&#62;注册表&#62;参数文件字符集要求一致，但是语言设置却可以不同，语言设置建议用英文。如字符集是zhs16gbk，则nls_lang可以是American_America.zhs16gbk；如果字符集是utf8，则要改成SIMPLIFIED CHINESE_CHINA.AL32UTF8。(即hkey_local_machine =&#62; software =&#62; oracle =&#62;NLS_LANG改为SIMPLIFIED CHINESE_CHINA.AL32UTF8)
2.迁移过程中字符编码转换不正确，如何转换编码可参照总结1。在php中，可以使用mb_string 的mb_detect_encoding来检测字符串是什么编码。
3.脚本代码要另存为utf8格式。
4.页面的header 要设置为utf8。
&#160;
]]></description>
			<content:encoded><![CDATA[<p>&nbsp;今天早上，网页忽然正常显示了，原来是修改了注册表的原因。<br />&nbsp;在数据库迁移后(sql server :gbk2312 到 Oracle : UTF8)，可能出现页面字符乱码的原因：</p>
<p>1.oracle字符集设置不正确。</p>
<pre>数据库服务器字符集select * from nls_database_parameters，其来源于props$，是表示数据库的字符集。客户端字符集环境select * from nls_instance_parameters,其来源于v$parameter，表示客户端的字符集的设置。可能是参数文件，环境变量或者是注册表会话字符集环境select * from nls_session_parameters，其来源于v$nls_parameters，表示会话自己的设置，可能是会话的环境变量或者是alter session完成，如果会话没有特殊的设置，将与nls_instance_parameters一致。

客户端的字符集要求与服务器一致，才能正确显示数据库的非Ascii字符。如果多个设置存在的时候，alter session&gt;环境变量&gt;注册表&gt;参数文件字符集要求一致，但是语言设置却可以不同，语言设置建议用英文。如字符集是zhs16gbk，则nls_lang可以是American_America.zhs16gbk；如果字符集是utf8，则要改成SIMPLIFIED CHINESE_CHINA.AL32UTF8。(即hkey_local_machine =&gt; software =&gt; oracle =&gt;NLS_LANG改为SIMPLIFIED CHINESE_CHINA.AL32UTF8)</pre>
<p>2.迁移过程中字符编码转换不正确，如何转换编码可参照总结1。<br />在php中，可以使用mb_string 的mb_detect_encoding来检测字符串是什么编码。</p>
<p>3.脚本代码要另存为utf8格式。</p>
<p>4.页面的header 要设置为utf8。</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://ringtail.xmulib.org/2008/05/07/%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%bc%96%e7%a0%81%e8%bd%ac%e6%8d%a2%e5%b0%8f%e7%bb%932/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework中对oracle数据库操作总结</title>
		<link>http://ringtail.xmulib.org/2007/12/18/zend-framework%e4%b8%ad%e5%af%b9oracle%e6%95%b0%e6%8d%ae%e5%ba%93%e6%93%8d%e4%bd%9c%e6%80%bb%e7%bb%93/</link>
		<comments>http://ringtail.xmulib.org/2007/12/18/zend-framework%e4%b8%ad%e5%af%b9oracle%e6%95%b0%e6%8d%ae%e5%ba%93%e6%93%8d%e4%bd%9c%e6%80%bb%e7%bb%93/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 01:47:37 +0000</pubDate>
		<dc:creator>ringtail</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[zendframework]]></category>

		<guid isPermaLink="false">http://ringtail.xmulib.org/2007/12/18/zend-framework%e4%b8%ad%e5%af%b9oracle%e6%95%b0%e6%8d%ae%e5%ba%93%e6%93%8d%e4%bd%9c%e6%80%bb%e7%bb%93/</guid>
		<description><![CDATA[ZF中对Oracle的简单操作总结，仅结合自身经验
]]></description>
			<content:encoded><![CDATA[<p>说明： 摘自<a href="http://www.phpeye.com/zf/zend.db.html"><b>ZF手册中文版</b> </a><br />1.执行查询并返回结果<br /><a href="#next">跳过废话</a><br />1.1 使用 <code>Zend_Db_Adapter</code><br />&nbsp;一旦你得到了一个<code>Zend_Db_Adapter</code> 实例, 你可以直接<br />
执行sql语句进行查询.  <code>Zend_Db_Adapter</code> 传送这些sql语<br />
句到底层的PDO对象，由PDO对象组合并执行他们，在有查询结果的情况<br />
下，返回一个PDOStatement对象以便对结果进行处理。<br /><code></code></p>
<pre>&lt;?php

// 创建一个$db对象,然后查询数据库// 使用完整的sql语句直接进行查询.$sql = $db-&gt;quoteInto(    'SELECT * FROM example WHERE date &gt; ?',    '2006-01-01');$result = $db-&gt;query($sql);

// 使用PDOStatement对象$result将所有结果数据放到一个数组中$rows = $result-&gt;fetchAll();

?&gt;</pre>
<p>或者使用fetch开头系列方法获得结果集：
<p>对于每一种 <code>fetch系列 </code>的方法来说，你需<br />
要传送一个select的sql语句；假如你在操作语句中使用指定的占位符，你也可以<br />
传送一个绑定数据的数组对你的操作语句进行处理和替换。 <code>Fetch系列 </code><br />
的方法包括：
</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p><code>fetchAll()</code></p>
</li>
<li>
<p><code>fetchAssoc()</code></p>
</li>
<li>
<p><code>fetchCol()</code></p>
</li>
<li>
<p><code>fetchOne()</code></p>
</li>
<li>
<p><code>fetchPairs()</code></p>
</li>
<li>
<p><code>fetchRow()</code></p>
</li>
</ul>
<p>
<pre>&lt;?php

// 创建一个 $db对象, 然后...

// 取回结果集中所有字段的值,作为连续数组返回$result = $db-&gt;fetchAll(    "SELECT * FROM round_table WHERE noble_title = :title",    array('title' =&gt; 'Sir'));

// 取回结果集中所有字段的值,作为关联数组返回// 第一个字段作为码$result = $db-&gt;fetchAssoc(    "SELECT * FROM round_table WHERE noble_title = :title",    array('title' =&gt; 'Sir'));

// 取回所有结果行的第一个字段名$result = $db-&gt;fetchCol(    "SELECT first_name FROM round_table WHERE noble_title = :title",    array('title' =&gt; 'Sir'));

// 只取回第一个字段值$result = $db-&gt;fetchOne(    "SELECT COUNT(*) FROM round_table WHERE noble_title = :title",    array('title' =&gt; 'Sir'));

// 取回一个相关数组,第一个字段值为码// 第二个字段为值$result = $db-&gt;fetchPairs(    "SELECT first_name, favorite_color FROM round_table WHERE noble_title = :title",    array('title' =&gt; 'Sir'));

// 只取回结果集的第一行$result = $db-&gt;fetchRow(    "SELECT * FROM round_table WHERE first_name = :name",    array('name' =&gt; 'Lancelot'));

?&gt;</pre>
</div>
<p>1.2 使用Zend_Db_Select方法
<p>
使用Zend_Db_Select方法是一种不受数据库约束构建select的sql语句的工具<br />
（ares注：用户可以使用该方法生成查询的sql语句，而不需要考虑各种数据<br />
库sql语句的差别）。虽然该方法明显还不完善，但是的确为我们提供一种方<br />
法，帮助我们在不同的后台数据库进行相同的查询工作。除此之外，它还可<br />
以避免sql语句攻击。
</p>
<p>
创建一个zend_db_select实例最简单的方法就是使用zend_db_adapter::select()方法 </p>
<p></p>
<pre>&lt;? php

//在model中取得连接，并进行相应数据库操作

$this-&gt;db = Zend_Registry::get('db');&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 

$select = $this-&gt;db-&gt;select(); $select-&gt;from('link_info', 'link_info.*') &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; -&gt;join('link_tag_collect', 'link_info.linkid=link_tag_collect.linkid') &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; -&gt;where('user_friend.userid=?',$userid)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;distinct(link_info.linkid)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; -&gt;order('link_tag_collect.addtime DESC') &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; -2007-12-18&gt;limit(10,0); $sql = $select-&gt;__toString(); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  $result = $this-&gt;db-&gt;fetchALL($sql); 

?&gt;</pre>
<p>1.3 使用 Zend_Db_Table<br />Zend_Db_Table 是Zend Framework的表模块.它通过zend_db_adapter连接到数据库,为数据库模式检查表对象,<br />并对该表进行操作和查询.
<pre>&lt;?phpclass RoundTable extends Zend_Db_Table {}

$table = new RoundTable();$db = $table-&gt;getAdapter();

// SELECT * FROM round_table//     WHERE noble_title = "Sir"//     ORDER BY first_name//     LIMIT 10 OFFSET 20

$where = $db-&gt;quoteInto('noble_title = ?', 'Sir');$order = 'first_name';$count = 10;$offset = 20;

$rowset = $table-&gt;fetchAll($where, $order, $count, $offset);?&gt;</pre>
<p>以上都为废话，从ZF手册中皆能得到。
<div id="next">在实际中，我最常使用的是</div>
<p>
<ul>
<li>从model中获得数据库连接，然后使用ZEND_DB_SELECT。</li>
</ul>
<p>在tag.php中
<pre>&lt;?php&nbsp;public function getTopTag(){&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $select = $this-&gt;db-&gt;select();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $select-&gt;from($this-&gt;_name, '*')&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; -&gt;order('TAGTOTAL DESC')&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; -&gt;limit(10,0);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $sql = $select-&gt;__toString();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $result = $this-&gt;db-&gt;fetchALL($sql);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return $result;&nbsp;&nbsp;&nbsp; }?&gt;</pre>
<p>在TagController.php中
<pre>&lt;?phpclass TagController extends Zend_Controller_Action	private $tag;	function init() {		parent::init();		Zend_Loader::loadClass('Tag');				$this-&gt;tag = new Tag();			}	function topAction(){		$thi-&gt;tag-&gt;getTopTag();		...	}?&gt;</pre>
<p>
<ul>
<li>使用ZEND_DB_TABLE</li>
</ul>
<p>在Tag.php中</p>
<pre>&lt;?phpclass Tag extends Zend_Db_Table{    protected $_name = "TAG_INFO";    protected $_primary = 'TAGID';}?&gt;在TagController.php中&lt;?phpclass TagController extends Zend_Controller_Action	private $tag;	function init() {		parent::init();		Zend_Loader::loadClass('Tag');				$this-&gt;tag = new Tag();			}	function topAction(){		$order = 'TAGTOTAL';			$count = 10;		$offset = 0;&nbsp;		$thi-&gt;tag-&gt;fetchAll( $order, $count, $offset);		...	}?&gt;</pre>
<p>最好还是选用方法一，能够将对数据的操作都封装在model中。<br />2.插入数据<br />无论是DB还是Table类，都使用insert()方法。<br />对于Oracle来说，如果要使用sequence作为自增的主键的话，需要使用trigger。<br />比如，有tag表，主键为tagid，其对应的sequence为tag_seq,要插入数据时，需要先新建trigger：</p>
<p>create or replace trigger tag_tri<br />before insert on tag<br />for each row<br />declare<br />nextid number;<br />begin<br />IF :new.tagid IS NULL or :new.tagid=0 THEN<br />select tag_seq.nextval<br />into nextid<br />from sys.dual;<br />:new.tagid:=nextid;<br />end if;<br />end tag_tri;</p>
<p>其余部分和插入其它数据库相同
<pre>&lt;?php$table_name='TAG';$row = array (		'TAGNAME'   =&gt; $tagname,		'TAGTOTAL'  =&gt; '1'	);$this-&gt;db-&gt;insert($table_name,$row);?&gt;</pre>
<p>3.更新数据<br />3.1直接执行update语句，参见文档。<br />3.2如果update语句中，有包含数据库的特殊关键字时，需要先将数据选出，然后再更新
<pre>&lt;?php	$where = $this-&gt;db-&gt;quoteInto('tagname = ?',$tagname);	$rowset = $this-&gt;tag-&gt;fetchAll($where);	$count=$rowset-&gt;count();	$tag = $rowset-&gt;current();						if($count!=0){		$tagid=$tag-&gt;TAGID;		//tagtotal+1

		$tag-&gt;TAGTOTAL ++;  //应判断一下当前用户是否		$tag-&gt;save();		}?&gt;</pre>
<p>4.删除数据
<pre>&lt;?php	//删除已有的collect表中记录	// where条件语句	$where = $this-&gt;db-&gt;quoteInto('USERID = ?', $userid)		.$this-&gt;db-&gt;quoteInto('AND LINKID = ?', $linkid);

	// 删除数据并得到影响的行数	$rows_affected =  $this-&gt;collect-&gt;delete($where);?&gt;</pre>
<p>总结完毕：<br />tips：<br />注意表名、字段名等的大小写！</p>
]]></content:encoded>
			<wfw:commentRss>http://ringtail.xmulib.org/2007/12/18/zend-framework%e4%b8%ad%e5%af%b9oracle%e6%95%b0%e6%8d%ae%e5%ba%93%e6%93%8d%e4%bd%9c%e6%80%bb%e7%bb%93/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
