<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[php版的jquery，php 处理DOM利器–phpQuery  ，服务端的php jquerylib。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Fri, 06 Jul 2012 06:31:35 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	http://www.cnblogs.com/in-loading/archive/2012/04/11/2442697.html<br/><br/>http://code.google.com/p/phpquery<br/>发现已经有人做的相当完备了<br/>http://stackoverflow.com/questions/260605/php-css-selector-library<br/>----------------------------------------------------------------------------------------------<br/>JQuery是一个非常著名的JS框架，提供了对DOM文档的完整操作。这个文档处理利器现在终于有了PHP版，也就是说可以使用php操作 HTML或者XML文档，遍历文档的节点，很轻松的取出，填充节点内容。或者简单来说，除了js的事件响应部分，其余的几乎都可以用php来实现。php 对数据处理的能力显然要比JS强大很多，对不熟悉JS的同学来说，phpQuery是个非常强大的帮手。如果了解了phpQuery，那么就很容易理解其 实phpQuery也可以取代一部分Smarty的功能。<br/><br/>我刚刚开始学习使用phpQuery，这应该算一篇学习笔记，我会努力将其向手册风格靠拢，不过不会做成中文手册，仍然会加入我在使用过程中遇到的问题以及解决方案。<br/><br/>开始phpQuery<br/>参考资料：phpQuery JQuery<br/><br/>phpQuery从编程思想到语言风格都是参照JQuery来做的，所以熟悉JQuery的人可以随时对照参考JQuery手册，方便理解。<br/><br/>phpQuery应用举例：<br/><br/>require(’phpQuery/phpQuery.php’);<br/>$file = file_get_contents(”test_phpQuery.html”);<br/>$dom = phpQuery::newDocument($file);&nbsp;&nbsp;//初始化对象<br/><br/>echo pq(”head &gt; title”)-&gt;text(); //输出文档title<br/><br/>pq这个全局函数类似于JQuery中的$()符号，用于执行请求，或者遍历DOM节点。<br/>例子中的”head &gt; title”就是一个选择请求，选择head标签下的title子标签。<br/><br/>pq(”li”); //选择所有文档中的li标签<br/>foreach(pq(”li”) as $item)<br/>=======================================================================<br/>这篇文章主要介绍了phpQuery让php处理html代码像jQuery一样方便,需要的朋友可以参考下<br/> <br/>简介<br/>如何在php中方便地解析html代码，估计是每个phper都会遇到的问题。用phpQuery就可以让php处理html代码像jQuery一样方便。<br/>项目地址：https://code.google.com/p/phpquery/<br/>github地址：https://github.com/TobiaszCudnik/phpquery<br/>DEMO<br/>下载库文件：https://code.google.com/p/phpquery/downloads/list<br/>我下的是onefile版：phpQuery-0.9.5.386-onefile.zip<br/>官方demo：https://code.google.com/p/phpquery/source/browse/branches/dev/demo.php<br/>然后在项目中引用。<br/>html文件test.html：<br/><textarea name="code" class="php" rows="15" cols="100"> 
&lt;div class=&quot;thumb&quot; id=&quot;Thumb-13164-3640&quot; style=&quot;position: absolute; left: 0px; top: 0px;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;/Spiderman-City-Drive&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;img src=&quot;/thumb/12/Spiderman-City-Drive.jpg&quot; style=&quot;border-left-color: rgb(0, 153, 204); border-left-width: 1px; border-left-style: solid; padding: 0px 3px; margin: 3px auto 0px; width: 640px; background-color: rgb(242, 246, 251); clear: both; border-top-color: rgb(0, 153, 204); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(0, 153, 204); border-right-width: 1px; border-right-style: solid;&quot;&gt; 复制代码代码如下:
</textarea><br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php
&nbsp;&nbsp;&nbsp;&nbsp;include(&#039;phpQuery-onefile.php&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;$filePath = &#039;test.html&#039;;
&nbsp;&nbsp;&nbsp;&nbsp;$fileContent = file_get_contents($filePath);
&nbsp;&nbsp;&nbsp;&nbsp;$doc = phpQuery::newDocumentHTML($fileContent);
&nbsp;&nbsp;&nbsp;&nbsp;phpQuery::selectDocument($doc);
&nbsp;&nbsp;&nbsp;&nbsp;$data = array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;name&#039; =&gt; array(),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;href&#039; =&gt; array(),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;img&#039; =&gt; array()
&nbsp;&nbsp;&nbsp;&nbsp;);
&nbsp;&nbsp;&nbsp;&nbsp;foreach (pq(&#039;a&#039;) as $t) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$href = $t -&gt; getAttribute(&#039;href&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data[&#039;href&#039;][] = $href;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;foreach (pq(&#039;img&#039;) as $img) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data[&#039;img&#039;][] = $domain . $img -&gt; getAttribute(&#039;src&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;foreach (pq(&#039;.GameName&#039;) as $name) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$data[&#039;name&#039;][] = $name -&gt; nodeValue;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;var_dump($data);
?&gt;
</textarea><br/>上面的代码中包含了取属性和innerText内容（通过nodeValue取）。<br/>输出：<br/> <br/>复制代码代码如下:<br/><br/>array (size=3)<br/>&nbsp;&nbsp;&#039;name&#039; =&gt; <br/>&nbsp;&nbsp;&nbsp;&nbsp;array (size=2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 =&gt; string &#039;Spiderman City Drive&#039; (length=20)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 =&gt; string &#039;Spiderman - City Raid&#039; (length=21)<br/>&nbsp;&nbsp;&#039;href&#039; =&gt; <br/>&nbsp;&nbsp;&nbsp;&nbsp;array (size=2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 =&gt; string &#039;http://www.gahe.com/Spiderman-City-Drive&#039; (length=40)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 =&gt; string &#039;http://www.gahe.com/Spiderman-City-Raid&#039; (length=39)<br/>&nbsp;&nbsp;&#039;img&#039; =&gt; <br/>&nbsp;&nbsp;&nbsp;&nbsp;array (size=2)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 =&gt; string &#039;http://www.gahe.com/thumb/12/Spiderman-City-Drive.jpg&#039; (length=53)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 =&gt; string &#039;http://www.gahe.com/thumb/12/Spiderman-City-Raid.jpg&#039; (length=52)<br/> <br/>强大的是pq选择器，语法类似jQuery，很方便。<br/>来自：http://www.aspku.com/kaifa/php/46348.html<br/><br/>更多参考：<br/>http://www.cnblogs.com/rmbteam/archive/2011/11/05/2236986.html<br/>实践示例：http://querylist.cc/article/9<br/><br/><br/><br/>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] php版的jquery，php 处理DOM利器–phpQuery  ，服务端的php jquerylib。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>