<?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>王超 - 博客 BLOG &#187; wangchao</title>
	<atom:link href="http://www.wangchao123.com/author/wangchao/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wangchao123.com</link>
	<description>code player 海盗精神 - 他们向往自由，面对大海胸怀宽广，只拿他们想要的，遵守契约，单纯而且机智。</description>
	<lastBuildDate>Tue, 07 Feb 2012 10:05:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>(转载) 使用PHP创建一个REST API(Create a REST API with PHP)</title>
		<link>http://www.wangchao123.com/2012/02/07/771</link>
		<comments>http://www.wangchao123.com/2012/02/07/771#comments</comments>
		<pubDate>Tue, 07 Feb 2012 07:32:18 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[手机]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=771</guid>
		<description><![CDATA[译者前言： 首先这是一篇国外的英文文章，非常系统、详尽的介绍了如何使用PHP创建REST API，国内这方面的资料非常非常的有限，而且基本没有可操作性。这篇文章写的非常好，只要对PHP稍有了解的程序员，看完本文基本可以自己动手写REST API，花了几个小时翻译过来和大家共享，希望可以帮助大家。转载请注明出处。 本文地址：http://hmw.iteye.com/blog/1190827 原文地址：Create a REST API with PHP One of the latest (sort of) crazes sweeping the net is APIs, more specifically those that leverage REST. It’s really no surprise either, as consuming REST APIs is so incredibly easy… in any language. It’s also incredibly easy to create them as you essentially [...]]]></description>
			<content:encoded><![CDATA[<p><span class="blog_content"><img src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2012/02/095428O0q.png" alt="" /> </span></p>
<p>译者前言：</p>
<p>首先这是一篇国外的英文文章，非常系统、详尽的介绍了如何使用PHP创建REST API，国内这方面的资料非常非常的有限，而且基本没有可操作性。这篇文章写的非常好，只要对PHP稍有了解的程序员，看完本文基本可以自己动手写REST API，花了几个小时翻译过来和大家共享，希望可以帮助大家。转载请注明出处。</p>
<p>本文地址：<a href="http://hmw.iteye.com/blog/1190827" target="_blank">http://hmw.iteye.com/blog/1190827</a></p>
<p>原文地址：<a href="http://www.gen-x-design.com/archives/create-a-rest-api-with-php" target="_blank">Create a REST API with PHP</a></p>
<p>One of the latest (sort of) crazes sweeping the net is APIs, more specifically those that leverage REST. It’s really no surprise either, as consuming REST APIs is so incredibly easy… in any language. It’s also incredibly easy to create them as you essentially use nothing more than an HTTP spec that has existed for ages. One of the few things that I give Rails credit for is its well thought-out REST support, both for providing and consuming these APIs (as its been explained by all the Rails fanboys I work with).</p>
<p><span style="color: darkred;">最近互联网上比较热门的一个名词是APIs（接口）,特别是leverage REST。不过考虑到REST APIs在任何语言下都是非常的简单，也就没什么好惊奇的了。同时，它也是非常的容易创建，你基本只需要使用已经存在多年的HTTP规范就可以。我认为Rails语言的为数不多的优点之一就是良好的REST支持，不仅是提供APIs，同时也有很多的客户端支持（我的一些Rails粉丝同事都向我解释了这一点）。</span></p>
<p>Seriously, if you’ve never used REST, but you’ve ever had to work with (or worse, create) a SOAP API, or simply opened a WSDL and had your head explode, boy do I have good news for you!</p>
<p><span style="color: darkred;">认真的讲，假如你从来没有使用过REST，却曾经使用过SOAP API，或者只是简单的打开一个令人头大的WSDL文档。小伙子，我确实要带给你一个好消息！</span></p>
<p>So, What on Earth is REST? Why Should You Care?</p>
<p><span style="color: darkred;">那么，究竟什么是REST？为什么你应该关心？</span></p>
<p>Before we get into writing some code, I want to make sure everyone’s got a good understanding of what REST is and how its great for APIs. First, technically speaking, REST isn’t specific to just APIs, it’s more of a generic concept. However, obviously, for the sake of this article we’ll be talking about it in the context of an API. So, let’s look at the basic needs of an API and how REST addresses them.</p>
<p><span style="color: darkred;">在我们开始写代码之前，我想要确认每个人都可以很好的理解什么是REST以及它是如何特别适合APIs的。首先，从技术上来讲，REST并不是仅仅特定于APIs应用，它更多的是一个通用的概念。然而，很明显，我们这篇文章所讨论的REST就是在接口应用的环境下。因此，让我们看看一个API的基本要求已经REST如何处理他们。</p>
<p></span></p>
<p><strong><span style="font-size: large;">Requests <span style="color: darkred;">请求</span></span></strong></p>
<p>All APIs need to accept requests. Typically, with a RESTful API, you’ll have a well-defined URL scheme. Let’s say you want to provide an API for users on your site (I know, I always use the “users” concept for my examples). Well, your URL structure would probably be something like, “api/users” and “api/users/[id]” depending on the type of operation being requested against your API. You also need to consider how you want to accept data. These days a lot of people are using JSON or XML, and I personally prefer JSON because it works well with JavaScript, and PHP has easy functionality for encoding and decoding it. If you wanted your API to be really robust, you could accept both by sniffing out the content-type of the request (i.e. application/json or application/xml), but it’s perfectly acceptable to restrict things to one content type. Heck, you could even use simple key/value pairs if you wanted.</p>
<p><span style="color: darkred;">所有的APIs都需要接收请求。对于一个RESTful API，你需要一个定义好的URL规则，我们假定你想要提供一个接口给你网站上的用户（我知道，我总是使用”用户”这个概念来举例）。你的URL结构可能类似于这样：”api/users”或者”api/users/[id]“，这取决于请求接口的操作类型。同时，你也需要考虑你想要怎么样接收数据。近来一段时间，很多人正在使用JSON或者XML，从我个人来讲，我更加喜欢JSON，因为它可以很好的和javascript进行交互操作，同时PHP也可以很简单的通过json_encode和json_decode两个函数来对它进行编码和解码。如果你希望自己的接口真正强健，你应该通过识别请求的内容类型（比如application/json或者application/xml）同时允许接收两种格式。但是，限制只接收一种类型的数据也是可以很好的被接受。真见鬼，假如你愿意，你甚至可以使用简单的键/值对。</span></p>
<p>The other piece of a request is what it’s actually meant to do, such as load, save, etc. Normally, you’d have to come up with some sort of architecture that defines what action the requester (consumer) desires, but REST simplifies that. By using HTTP request methods, or verbs, we don’t need to define anything. We can just use the GET, POST, PUT, and DELETE methods, and that covers every request we’d need. You can equate the verbs to your standard crud-style stuff: GET = load/retrieve, POST = create, PUT = update, DELETE = well, delete. It’s important to note that these verbs don’t directly translate to CRUD, but it is a good way to think about them. So, going back to the above URL examples, let’s take a look at what some possible requests could mean:</p>
<p>GET request to /api/users – List all users</p>
<p>GET request to /api/users/1 – List info for user with ID of 1</p>
<p>POST request to /api/users – Create a new user</p>
<p>PUT request to /api/users/1 – Update user with ID of 1</p>
<p>DELETE request to /api/users/1 – Delete user with ID of 1</p>
<p><span style="color: darkred;">一个请求的其他部分是它真正要做的事情，比如加载、保存等。通常来说，你应该提供几种结构来定义请求者（消费者）所希望的操作，但是REST简化了这些。通过使用HTTP请求方法或者动作，我们不需要去额外定义任何东西。我们可以仅仅使用GET,POST,PUT和DELETE方法，这些方法涵盖了我们所需要的每一个请求。你可以把它和标准的增删改查模式对应起来：GET=加载/检索(查，select)，POST=创建(增，Create)，PUT=更新(改，update),DELETE=删除(DELETE)。我们要注意到，这些动词并没有直接翻译成CRUD（增删改查）,但是这个理解它们的一个很好的方法。因此，回到刚才所举的URL的例子，让我们看一下一些可能的请求的含义：</p>
<p>GET request to /api/users – 列举出所有的用户</p>
<p>GET request to /api/users/1 – 列出ID为1的用户信息</p>
<p>POST request to /api/users – 插入一个新的用户</p>
<p>PUT request to /api/users/1 – 更新ID为1的用户信息</p>
<p>DELETE request to /api/users/1 – 删除ID为1的用户</span></p>
<p>As you hopefully see, REST has already taken care of a lot of the major headaches of creating your own API through some simple, well-understood standards and protocols, but there’s one other piece to a good API…</p>
<p><span style="color: darkred;">正如你所希望看到的，REST已经解决了很多令人头疼的创建接口的问题，通过一些简单的，容易理解的标准和协议。但是一个好的接口还要另外一个方面&#8230;</span></p>
<p><strong><span style="font-size: large;">Responses <span style="color: darkred;">响应</span></span></strong></p>
<p>So, REST handles requests very easily, but it also makes generating responses easy. Similar to requests, there are two main components of a RESTful response: the response body, and a status code. The response body is pretty easy to deal with. Like requests, most responses in REST are usually either JSON or XML (perhaps just plain text in the case of POSTs, but we’ll cover that later). And, like requests, the consumer can specify the response type they’d like through another part of the HTTP request spec, “Accept”. If a consumer wishes to receive an XML response, they’d just send an Accept header as a part of their request saying as much (”Accept: application/xml”). Admittedly, this method isn’t as widely adopted (tho it should be), so you have can also use the concept of an extension in the URL. For example, /api/users.xml means the consumer wants XML as a response, similarly /api/users.json means JSON (same for things like /api/users/1.json/xml). Either way you choose (I say do both), you should pick a default response type as a lot of the time people wont’ even tell you what they want. Again, I’d say go with JSON. So, no Accept header or extension (i.e. /api/users) should not fail, it should just fail-over to the default response-type.</p>
<p><span style="color: darkred;">所以，REST可以很简单的处理请求，同时它也可以简单的处理响应。和请求类似，一个RESTful的响应主要包括两个主要部分：响应体和状态码。响应体非常容易去处理。就像请求，大部分的REST响应通常是JSON或者XML格式（也许对POST操作来说仅仅是纯文本，我们稍后会讨论），和请求类似，消费者可以通过设置HTTP规范的”Accept”选项来规定自己做希望接收到的响应数据类型。如果一个消费者希望接收到XML响应，他们仅仅需要发送一个包含类似于(”Accept: application/xml”)这样的头信息请求。不可否认，这种方式并没有被广泛的采用（即使应该这样），因此你也可以使用URL后缀的形式，例如：/api/users.xml意味着消费者希望得到XML响应，同样，/api/users.json意味着JSON格式的响应（/api/users/1.json/xml也是一样）。不管你采用哪一种方法，你都需要设定一个默认的响应类型，因为很多时候人们并不会告诉你他们希望什么格式。再次地，我会选择JSON来讨论。所以，没有Accept头信息或者扩展（例如：/api/users）不应该失败，而是采用默认的响应类型。</span></p>
<p>But what about errors and other important status messages associated with requests? Easy, use HTTP status codes! This is far and above one of my favorite things about creating RESTful APIs. By using HTTP status codes, you don’t need to come up with a error / success scheme for your API, it’s already done for you. For example, if a consumer POSTS to /api/users and you want to report back a successful creation, simply send a 201 status code (201 = Created). If it failed, send a 500 if it failed on your end (500 = Internal Server Error), or perhaps a 400 if they screwed up (400 = Bad request). Maybe they’re trying to POST against an API endpoint that doesn’t accept posts… send a 501 (Not implemented). Perhaps your MySQL server is down, so your API is temporarily borked… send a 503 (Service unavailable). Hopefully, you get the idea. If you’d like to read up a bit on status codes, check them out on wikipedia: List of HTTP Status Codes.</p>
<p><span style="color: darkred;">但是和请求有关的错误和其他重要的状态信息怎么办呢？简单，使用HTTP的状态码！这是我创建RESTful接口最喜欢的事情之一。通过使用HTTP状态码，你不需要为你的接口想出error/success规则，它已经为你做好。比如：假如一个消费者提交数据（POST）到/api/users，你需要返回一个成功创建的消息，此时你可以简单的发送一个201状态码（201=Created)。如果失败了，服务器端失败就发送一个500（500=内部服务器错误），如果请求中断就发送一个400（400=错误请求）。也许他们会尝试向一个不接受POST请求的接口提交数据，你就可以发送一个501错误（未执行）。又或者你的MySQL服务器挂了，接口也会临时性的中断，发送一个503错误（服务不可用）。幸运的是，你已经知道了这些，假如你想要了解更多关于状态码的资料，可以在维基百科上查找：List of HTTP Status Codes。</span></p>
<p>I’m hoping you see all the advantages you get by leveraging the concepts of REST for your APIs. It really is super-cool, and its a shame its not more widely talked about in the PHP community (at least as far as I can tell). I think this is likely due to the lack of good documentation on how to deal with requests that aren’t GET or POST, namely PUT and DELETE. Admittedly, it is a bit goofy dealing with these, but it certainly isn’t hard. I’m also sure some of the popular frameworks out there probably have some sort of REST implementation, but I’m not a huge framework fan (for a lot of reasons that I won’t get into), and it’s also good to know these things even if somebody’s already created the solution for you.</p>
<p><span style="color: darkred;">我希望你能看到REST接口的这些优点。它真的超级酷。在PHP社区社区里没有被广泛的讨论真是非常的遗憾（至少我知道的是这样）。我觉得这主要是由于没有很好的文档介绍如何处理除了GET和POST之后的请求，即PUT和DELETE。不可否认，处理这些是有点傻，但是却不难。我相信一些流行的框架也许已经有了某种REST的实现方式，但是我不是一个框架粉丝（原因有很多），并且即使有人已经为你提供了解决方案，你知道这些也是非常有好处的。</span></p>
<p>If you’re still not convinced that this is a useful API paradigm, take a look at what REST has done for Ruby on Rails. One of its major claims to fame is how easy it is to create APIs (through some sort of RoR voodoo, I’m sure), and rightly so. Granted I know very little about RoR, but the fanboys around the office have preached this point to me many times. But, I digress… let’s write some code!</p>
<p><span style="color: darkred;">如果你还是不太自信这是一个非常有用的API范式，看一下REST已经为Ruby on Rails做了什么。其中最令人称道的就是创建接口的便利性（通过某种RoR voodoo，我确信），而且确实如此。虽然我对RoR了解很少，但是办公室的Ruby粉丝们向我说教过很多次。不好意思跑题了，让我们开始写代码。</span></p>
<p><strong><span style="font-size: large;">Getting Started with REST and PHP <span style="color: darkred;">开始使用PHP写REST</span></span></strong></p>
<p>One last disclaimer: the code we’re about to go over is in no way intended to be used as an example of a robust solution. My main goal here is to show how to deal with the individual components of REST in PHP, and leave creating the final solution up to you.</p>
<p><span style="color: darkred;">最后一项免责声明：我们接下来提供的代码并不能被用来作为一个稳健的解决方案。我的主要目的是向大家展示如果使用PHP处理REST的每个单独部分，而把最后的解决方案留给你们自己去创建。</span></p>
<p>So, let’s dig in! I think the best way to do something practical is to create a class that will provide all the utility functions we need to create a REST API. We’ll also create a small class for storing our data. You could also then take this, extend it, and apply it to your own needs. So, let’s stub some stuff out:</p>
<p><span style="color: darkred;">那么，让我们开始深入代码。我认为做一个实际事情做好的方法就是新建一个class，这个class将提供创建REST API所需要的所有功能性方法。现在我们新建一个小的class来存储我们的数据。你可以把它拿去扩展一下然后应用到自己的需求中。我们现在开始写点东西：</span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> RestUtils
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> processRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> sendResponse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'text/html'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getStatusCodeMessage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// these could be stored in a .ini file and loaded</span>
		<span style="color: #666666; font-style: italic;">// via parse_ini_file()... however, this will suffice</span>
		<span style="color: #666666; font-style: italic;">// for an example</span>
        <span style="color: #666666; font-style: italic;">// 这些应该被存储在一个.ini的文件中，然后通过parse_ini_file()函数来解析出来，然而这样也足够了，比如：</span>
		<span style="color: #000088;">$codes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span>
		    <span style="color: #cc66cc;">100</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Continue'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">101</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Switching Protocols'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">200</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'OK'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">201</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Created'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">202</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Accepted'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">203</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Non-Authoritative Information'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">204</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'No Content'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">205</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Reset Content'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">206</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Partial Content'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">300</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Multiple Choices'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">301</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Moved Permanently'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">302</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Found'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">303</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'See Other'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">304</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Not Modified'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">305</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Use Proxy'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">306</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'(Unused)'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">307</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Temporary Redirect'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">400</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Bad Request'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">401</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Unauthorized'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">402</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Payment Required'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">403</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Forbidden'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">404</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Not Found'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">405</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Method Not Allowed'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">406</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Not Acceptable'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">407</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Proxy Authentication Required'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">408</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Request Timeout'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">409</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Conflict'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">410</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Gone'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">411</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Length Required'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">412</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Precondition Failed'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">413</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Request Entity Too Large'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">414</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Request-URI Too Long'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">415</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Unsupported Media Type'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">416</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Requested Range Not Satisfiable'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">417</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Expectation Failed'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">500</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Internal Server Error'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">501</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Not Implemented'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">502</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Bad Gateway'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">503</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Service Unavailable'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">504</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Gateway Timeout'</span><span style="color: #339933;">,</span>
		    <span style="color: #cc66cc;">505</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'HTTP Version Not Supported'</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$codes</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$codes</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> RestRequest
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$request_vars</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$http_accept</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$method</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request_vars</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span>				<span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">http_accept</span>		<span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_ACCEPT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'json'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'json'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'xml'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">method</span>			<span style="color: #339933;">=</span> <span style="color: #0000ff;">'get'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setData<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setMethod<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">method</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$method</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setRequestVars<span style="color: #009900;">&#40;</span><span style="color: #000088;">$request_vars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request_vars</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$request_vars</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">method</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getHttpAccept<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">http_accept</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getRequestVars<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request_vars</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span style="color: #8b0000;"><br />
</span></p>
<p><span class="blog_content">OK, so what we’ve got is a simple class for storing some information about our request (RestRequest), and a class with some static functions we can use to deal with requests and responses. As you can see, we really only have two functions to write… which is the beauty of this whole thing! Right, let’s move on… <br />
Processing the Request <br />
<span style="color: darkred">好，现在我们有了一个简单的class来存储request的一些信息（RestRequest），和一个提供几个静态方法的class来处理请求和响应。就像你能看到的，我们还有两个方法要去写，这才是整个代码的关键所在，让我们继续&#8230;</span> </p>
<p>Processing the request is pretty straight-forward, but this is where we can run into a few catches (namely with PUT and DELETE… mostly PUT). We’ll go over those in a moment, but let’s examine the RestRequest class a bit. If you’ll look at the constructor, you’ll see that we’re already interpreting the HTTP_ACCEPT header, and defaulting to JSON if none is provided. With that out of the way, we need only deal with the incoming data. <br />
<span style="color: darkred">处理请求的过程非常直接，但是这才是我们可以有所收获的地方（即PUT/DELETE，大多数是PUT），我们接下来将会讨论这些。但是让我们先来检查一下RestRequest这个class，在构造方法中，你会看到我们已经处理了HTTP_ACCEPT的头信息，并且将JSON作为默认值。这样，我们就只需要处理传入的数据。</span> </p>
<p>There are a few ways we could go about doing this, but let’s just assume that we’ll always get a key/value pair in our request: ‘data’ =&gt; actual data. Let’s also assume that the actual data will be JSON. As stated in my previous explanation of REST, you could look at the content-type of the request and deal with either JSON or XML, but let’s keep it simple for now. So, our process request function will end up looking something like this: <br />
<span style="color: darkred">我们有几个方法可以选择，但是让我们假设在请求信息的总是可以接收到键/值对：&#8217;data&#8217;=&gt;真实数据。同时假设真实数据是JSON格式的。正如我前文所述，你可以根据请求的内容类型来处理JSON或者XML，但是让我们现在简单一点。那么，我们处理请求的方法将会类似于这样：</span> </span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> processRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// get our verb 获取动作</span>
    <span style="color: #000088;">$request_method</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_METHOD'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$return_obj</span>		<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RestRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// we'll store our data here 在这里存储请求数据</span>
    <span style="color: #000088;">$data</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;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$request_method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// gets are easy...</span>
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'get'</span><span style="color: #339933;">:</span>
            <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// so are posts</span>
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">:</span>
            <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// here's the tricky bit...</span>
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'put'</span><span style="color: #339933;">:</span>
            <span style="color: #666666; font-style: italic;">// basically, we read a string from PHP's special input location,</span>
            <span style="color: #666666; font-style: italic;">// and then parse it out into an array via parse_str... per the PHP docs:</span>
            <span style="color: #666666; font-style: italic;">// Parses str  as if it were the query string passed via a URL and sets</span>
            <span style="color: #666666; font-style: italic;">// variables in the current scope.</span>
            <span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'php://input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$put_vars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$put_vars</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// store the method</span>
    <span style="color: #000088;">$return_obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMethod</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request_method</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// set the raw data, so we can access it if needed (there may be</span>
    <span style="color: #666666; font-style: italic;">// other pieces to your requests)</span>
    <span style="color: #000088;">$return_obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRequestVars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <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;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// translate the JSON to an Object for use however you want</span>
        <span style="color: #000088;">$return_obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setData</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$return_obj</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span class="blog_content">Like I said, pretty straight-forward. However, a few things to note… First, you typically don’t accept data for DELETE requests, so we don’t have a case for them in the switch. Second, you’ll notice that we store both the request variables, and the parsed JSON data. This is useful as you may have other stuff as a part of your request (say an API key or something) that isn’t truly the data itself (like a new user’s name, email, etc.). <br />
<span style="color: darkred">正如我刚才所说的，非常的简单直接高效。然后，有几点需要注意：首先，我们不接受DELETE请求，因此我们在switch中不提供相应的case条件。其次，你会注意到我们把请求参数和解析后的JSON数据都存储起来了，这在请求中有其他需要处理的数据时会变得非常有用（API key或者其他），这些并不是请求的数据本身（比如一个新用户的名字、电子邮箱等）。</span> </p>
<p>So, how would we use this? Let’s go back to the user example. Assuming you’ve routed your request to the correct controller for users, we could have some code like this: <br />
<span style="color: darkred">那么，我们如何使用它呢？让我们回到刚才user的例子。假设你已经通过路由把请求对应到正确的users控制器，代码如下：</span> </span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> RestUtils<span style="color: #339933;">::</span><span style="color: #004000;">processRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMethod</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'get'</span><span style="color: #339933;">:</span>
		<span style="color: #666666; font-style: italic;">// retrieve a list of users</span>
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">first_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// just for example, this should be done cleaner</span>
		<span style="color: #666666; font-style: italic;">// and so on...</span>
		<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// etc, etc, etc...</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span class="blog_content">Please don’t do this in a real app, this is just a quick-and-dirty example. You’d want to wrap this up in a nice control structure with everything abstracted properly, but this should help you get an idea of how to use this stuff. But I digress, let’s move on to sending a response. <br />
Sending the Response <br />
<span style="color: darkred">请不要在真实的应用中这样做，这是一个非常快速和不干净的示例。你应该使用一个设计良好的控制结构来把它包裹起来，适当的抽象化，但是这样有助于你理解如何使用这些东西。让我们继续代码，发送一个响应信息。</span> </p>
<p>Now that we can interpret the request, let’s move on to sending the response. We already know that all we really need to do is send the correct status code, and maybe some body (if this were a GET request, for example), but there is an important catch to responses that have no body. Say somebody made a request against our sample user API for a user that doesn’t exist (i.e. api/user/123). The appropriate status code to send is a 404 in this case, but simply sending the status code in the headers isn’t enough. If you viewed that page in your web browser, you would get a blank screen. This is because Apache (or whatever your web server runs on) isn’t sending the status code, so there’s no status page. We’ll need to take this into account when we build out our function. Keeping all that in mind, here’s what the code should look like: <br />
<span style="color: darkred">既然我们已经可以解析请求，那么接下来我们继续来发送一个响应。我们已经知道我们真正需要去做的是发送一个正确的状态码和一些响应消息体（例如这是一个GET请求），但是对于没有消息体的响应来说有一个重要的catch（译者：不好意思，实在是不知道如何翻译这个词）。假定某个人向我们的user接口发送一个请求某个用户信息的请求，而这个用户却不存在（比如：api/user/123），此时系统发送最合适的状态码是404。但是简单的在头信息中发送状态码是不够的，如果你通过网页浏览器浏览该页面，你会看到一个空白页面。这是因为apache服务器（或者其他服务器）并不会发送此状态码，因此没有状态页面。我们需要在构建方法的时候考虑到这一点。把所有的东西都考虑进去，代码会类似于下面这样：</span> </span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> sendResponse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'text/html'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$status_header</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'HTTP/1.1 '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$status</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' '</span> <span style="color: #339933;">.</span> RestUtils<span style="color: #339933;">::</span><span style="color: #004000;">getStatusCodeMessage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// set the status</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status_header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// set the content type</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$content_type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// pages with body are easy</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$body</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// send the body</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$body</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// we need to create the body if none is passed</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// create some body messages</span>
        <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// this is purely optional, but makes the pages a little nicer to read</span>
        <span style="color: #666666; font-style: italic;">// for your users.  Since you won't likely send a lot of different status codes,</span>
        <span style="color: #666666; font-style: italic;">// this also shouldn't be too ponderous to maintain</span>
        <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">401</span><span style="color: #339933;">:</span>
                <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'You must be authorized to view this page.'</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">404</span><span style="color: #339933;">:</span>
                <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'The requested URL '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' was not found.'</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">:</span>
                <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'The server encountered an error processing your request.'</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">501</span><span style="color: #339933;">:</span>
                <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'The requested method is not implemented.'</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// servers don't always have a signature turned on (this is an apache directive &quot;ServerSignature On&quot;)</span>
        <span style="color: #000088;">$signature</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_SIGNATURE'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_SOFTWARE'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' Server at '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' Port '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_PORT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_SIGNATURE'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// this should be templatized in a real-world solution</span>
        <span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
                    &lt;html&gt;
                        &lt;head&gt;
                            &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;
                            &lt;title&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$status</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' '</span> <span style="color: #339933;">.</span> RestUtils<span style="color: #339933;">::</span><span style="color: #004000;">getStatusCodeMessage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/title&gt;
                        &lt;/head&gt;
                        &lt;body&gt;
                            &lt;h1&gt;'</span> <span style="color: #339933;">.</span> RestUtils<span style="color: #339933;">::</span><span style="color: #004000;">getStatusCodeMessage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/h1&gt;
                            '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'
&nbsp;
                            &lt;hr /&gt;
                            &lt;address&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$signature</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/address&gt;
                        &lt;/body&gt;
                    &lt;/html&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$body</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span class="blog_content">That’s It! We technically have everything we need now to process requests and send responses. Let’s talk a bit more about why we need to have a standard body response or a custom one. For GET requests, this is pretty obvious, we need to send XML / JSON content instead of a status page (provided the request was valid). However, there’s also POSTs to deal with. Inside of your apps, when you create a new entity, you probably fetch the new entity’s ID via something like mysql_insert_id(). Well, if a user posts to your API, they’ll probably want that new ID as well. What I’ll usually do in this case is simply send the new ID as the body (with a 201 status code), but you could also wrap that in XML or JSON if you’d like. <br />
<span style="color: darkred">就这样，从技术上来说，我们已经具备了处理请求和发送响应的所有东西。下面我们再讨论以下为什么我们需要一个标准的相应提或者一个自定义的。对于GET请求来说，非常明显，我们需要发送XML/JSON内容而不是一个状态页（假设请求是合法的）。然后，我们还有POST请求要去处理。在你的应用内部，当你创建一个新的实体，你也许需要使用通过类似于mysql_insert_id()这样的函数得到这个实体的ID。那么，当一个用户提交到你的接口，他们将很可能想要知道这个新的ID是什么。在这种情况下，我通常的做法是非常简单的把这个新ID作为响应的消息体发送给用户（同时发送一个201的状态码头信息），但是如果你愿意，你也可以使用XML或者JSON来把它包裹起来。</span> </p>
<p>So, let’s extend our sample implementation a bit: <br />
<span style="color: darkred">现在，让我们来扩展一下我们的例子，让它更加实际一点：</span> </span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMethod</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// this is a request for all users, not one in particular</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'get'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$user_list</span> <span style="color: #339933;">=</span> getUserList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// assume this returns an array</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHttpAccept</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'json'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			RestUtils<span style="color: #339933;">::</span><span style="color: #004000;">sendResponse</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_list</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'application/json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHttpAccept</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'xml'</span><span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// using the XML_SERIALIZER Pear Package</span>
			<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span>
			<span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">'indent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'     '</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'addDecl'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'rootName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$fc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				XML_SERIALIZER_OPTION_RETURN_RESULT <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
			<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$serializer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XML_Serializer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			RestUtils<span style="color: #339933;">::</span><span style="color: #004000;">sendResponse</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #339933;">,</span> <span style="color: #000088;">$serializer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_list</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'application/xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// new user create</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">:</span>
		<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">first_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// just for example, this should be done cleaner</span>
		<span style="color: #666666; font-style: italic;">// and so on...</span>
		<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// just send the new ID as the body</span>
		RestUtils<span style="color: #339933;">::</span><span style="color: #004000;">sendResponse</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">201</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span class="blog_content">Again, this is just an example, but it does show off (I think, at least) how little effort it takes to implement RESTful stuff. <br />
Wrapping Up <br />
<span style="color: darkred">再一次说明，这是一个例子，但它确实向我们展示了（至少我认为是）它能轻而易举的实现RESTful接口。</span> </p>
<p>So, that’s about it. I’m pretty confident that I’ve beaten the point that this should be quite easy into the ground, so I’d like to close with how you can take this stuff further and perhaps properly implement it. <br />
<span style="color: darkred">所以，这就是它。我非常的自信的说，我已经把这些解释的非常清楚。因此，我就不再赘述你如何具体实现它。</span> </p>
<p>In a real-world MVC application, what you would probably want to do is set up a controller for your API that loads individual API controllers. For example, using the above stuff, we’d possibly create a UserRestController which had four methods: get(), put(), post(), and delete(). The API controller would look at the request and determine which method to invoke on that controller. That method would then use the utils to process the request, do what it needs to do data-wise, then use the utils to send a response. <br />
<span style="color: darkred">在一个真实的MVC应用中，也许你想要做的就是为你的每个接口创建一个单独的控制器。例如，利用上面的东西，我们可以创建一个UserRestController控制器，这个控制器有四个方法，分别为：get(), put(), post(), 和 delete()。接口控制器将会查看请求类型然后决定哪个方法会被执行。这个方法会再使用工具来处理请求，处理数据，然后使用工具发送响应。</span> </p>
<p>You could also take it a step further than that, and abstract out your API controller and data models a bit more. Rather than explicitly creating a controller for every data model in your app, you could add some logic into your API controller to first look for an explicitly defined controller, and if none is found, try to look for an existing model. For example, the url “api/user/1″, would first trigger a lookup for a “user” rest controller. If none is found, it could then look for a model called “user” in your app. If one is found, you could write up a bit of automated voodoo to automatically process all the requests against those models. <br />
<span style="color: darkred">你也许会比现在更进一步，把你的接口控制器和数据模型抽象出来，而不是明确的为每一个数据模型创建控制器，你可以给你的接口控制器添加一些逻辑，先去查找一个明确定义好的控制器，如果没有，试着去查找一个已经存在的模型。例如：网址”api/user/1&#8243;将会首先触发查找一个叫user的最终控制器，如果没有，它会查找应用中叫user的模型，如果找到了，你可以写一个自动化的方法来自动处理所有请求这个模型的请求。</span> </p>
<p>Going even further, you could then make a generic “list-all” method that works similar to the previous paragraph’s example. Say your url was “api/users”. The API controller could first check for a “users” rest controller, and if none was found, recognize that users is pluaralized, depluralize it, and then look for a “user” model. If one’s found, load a list the list of users and send that off. <br />
<span style="color: darkred">再进一步，你可以建立一个通用的”list-all”方法，就像上面一段中的例子一样。假定你的url是”api/usrs”，接口控制器首先会查找叫users的控制器，如果没有找到，确认users是复数，把它变成单数，然后查找一个叫user的模型，如果找到了，加载一个用户列表然后把他们发送出去。</span> </p>
<p>Finally, you could add digest authentication to your API quite easily as well. Say you only wanted properly authenticated users to access your API, well, you could throw some code like this into your process request functionality (borrowed from an existing app of mine, so there’s some constants and variables referenced that aren’t defined in this snippet): <br />
<span style="color: darkred">最后，你可以给你的接口添加简单的身份验证。假定你仅仅希望适当的验证访问你的接口的用户，那么，你可以在处理请求的方法中添加类似于下面的一些代码（借用我的一个现有应用，因此有一些常量和变量在这个代码片段里面并没有被定义）：</span> <br />
</span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">			<span style="color: #666666; font-style: italic;">// figure out if we need to challenge the user</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_AUTH_DIGEST'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 401 Unauthorized'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WWW-Authenticate: Digest realm=&quot;'</span> <span style="color: #339933;">.</span> AUTH_REALM <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;,qop=&quot;auth&quot;,nonce=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">uniqid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;,opaque=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span>AUTH_REALM<span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// show the error if they hit cancel</span>
				<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>RestControllerLib<span style="color: #339933;">::</span><span style="color: #004000;">error</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">401</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// now, analayze the PHP_AUTH_DIGEST var</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> http_digest_parse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_AUTH_DIGEST'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$auth_username</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// show the error due to bad auth</span>
				<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>RestUtils<span style="color: #339933;">::</span><span style="color: #004000;">sendResponse</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">401</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// so far, everything's good, let's now check the response a bit more...</span>
			<span style="color: #000088;">$A1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> AUTH_REALM <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$auth_pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$A2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_METHOD'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uri'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$valid_response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$A1</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nonce'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nc'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cnonce'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'qop'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$A2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// last check..</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'response'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$valid_response</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span>RestUtils<span style="color: #339933;">::</span><span style="color: #004000;">sendResponse</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">401</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<div id="blog_content" class="blog_content">Pretty cool stuff, huh? With a little bit of code and some clever logic, you can add a fully functional REST API to your apps very quickly. I’m not just saying that to cheerlead the concept either, I implemented this stuff into one of my personal frameworks in about half a day, and then spent another half day adding all sorts of cool magic to it. If you (the reader) are interested in seeing my final implementation, drop me a note in the comments and I’d be happy to share it with you! Also, if you’ve got any cool ideas you’d like to share, be sure to drop those in the comments as well… if I like it enough, I’d even let you guest author your own article on the subject! <br />
	<span style="color: darkred">非常酷，对吧？通过少量的代码和一些智能的逻辑，你可以非常快速的给你的应用添加全功能的REST接口。我并不仅仅是支持这个概念，我已经在我个人的框架里面实现了这些东西，而这些仅仅花费了半天的时间，然后再花费半天时间添加一些非常酷的东西。如果你（读者）对我最终的实现感兴趣，请在评论中留言，我会非常乐趣和你分享它。同时，如果你有什么比较酷的想法，也欢迎通过评论和我进行分享。如果我足够喜欢它，我会邀请你在这里发表自己的文章。</span> </p>
<p>	Until next time… </p>
<p>	UPDATE: The much-requested follow-up to this article has been posted: Making RESTful Requests in PHP <br />
	<span style="color: darkred">更新：这篇文章的下一篇已经发表了，见：<a href="http://www.gen-x-design.com/archives/making-restful-requests-in-php/" target="_blank">Making RESTful Requests in PHP，使用PHP发送RESTfull请求</a></span> </div>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2012/02/07/771/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CVS 配置方法，及实时同步到真实代码 (实时发布)</title>
		<link>http://www.wangchao123.com/2011/12/05/746</link>
		<comments>http://www.wangchao123.com/2011/12/05/746#comments</comments>
		<pubDate>Mon, 05 Dec 2011 09:51:05 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[开发工具软件]]></category>
		<category><![CDATA[服务器 网络]]></category>
		<category><![CDATA[cvs]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=746</guid>
		<description><![CDATA[kill -9 `ps aux&#124;grep commitlog&#124;awk &#8216;{print $2}&#8217;` 建立帐号 #groupadd cvs #useradd  cvsroot -g cvs 检查是否存在cvs端口服务，防火墙需要打开2401的权限。 #more /etc/services &#124; grep cvspserver 看看是否有: cvspserver  2401/tcp #CVS client/server operations cvspserver  2401/udp #CVS client/server operations #vi /etc/xinetd.d/cvspserver service cvspserver { disable = no flags           = REUSE socket_type     = stream wait     [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">kill -9 `ps aux|grep commitlog|awk &#8216;{print $2}&#8217;`</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">建立帐号</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#groupadd cvs</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#useradd  cvsroot -g cvs</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">检查是否存在cvs端口服务，防火墙需要打开2401的权限。</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#more /etc/services | grep cvspserver</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">看看是否有:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">cvspserver  2401/tcp #CVS client/server operations</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">cvspserver  2401/udp #CVS client/server operations</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#vi /etc/xinetd.d/cvspserver</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">service cvspserver</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">disable = no</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">flags           = REUSE</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">socket_type     = stream</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">wait            = no</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">user            = root</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">server          = /usr/bin/cvs</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">server_args     = -f &#8211;allow-root=/fse/CVS_REP/cvs_docs   &#8211;allow-root=/fse/CVS_REP/cvs_classes pserver</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">log_on_failure  += USERID</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">初始化CVS</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#su cvsroot</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#cvs -d /fse/CVS_REP/cvs_docs init</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#cvs -d /fse/CVS_REP/cvs_classes init</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">重启服务</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#/etc/init.d/xinetd restart</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">检查CVS服务</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#netstat -l | grep cvspserver</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">此处需打开防火墙的 2401 端口（见1_linix.txt），可在windows cmd:<span style="white-space: pre;"> </span>telnet 192.168.1.199 2401 检查是否打开</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">导入程序</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">-先进入到网站的根目录下 cd /ROOT/www/docs</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">cvsroot$ cvs -d /fse/CVS_REP/cvs_docs import -m “new www” docs vendor_tag release_tag</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">分配cvs帐号的脚本 adduse</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#!/usr/bin/perl</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"># Simple script to take a username and password and</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"># return a line suitable for pasting into the CVS</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"># password file</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">// 添加用户</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"># exp: ./adduser.sh wangcy 123456 cvsroot &gt;&gt; cvs_other/CVSROOT/passwd</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">($u,$p,$g)=@ARGV;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@d=(A..Z,a..z);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">$s=$d[rand(52)].$d[rand52];</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">print $u.”:”.crypt($p,$s).”:”.$g.”\n”;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">提交cvs的同时发布新的代码到docs目录中</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#vi cvs_other/CVSROOT/loginfo 最后一行增加</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">docs /fse/CVS_REP/cvs_docs/CVSROOT/log.in %s -f /fse/CVS_REP/cvs_docs/CVSROOT/commitlog  -a /fse/docs</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">classes /fse/CVS_REP/cvs_classes/CVSROOT/log.in %s -f /fse/CVS_REP/cvs_classes/CVSROOT/commitlog  -a /fse/classes</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">log.in文件.&#8211;&gt;http://www.cnblogs.com/oxo/articles/472518.html</div>
<p>kill -9 `ps aux|grep commitlog|awk &#8216;{print $2}&#8217;`</p>
<p>______________________________________</p>
<p>建立帐号</p>
<p>#groupadd cvs</p>
<p>#useradd  cvsroot -g cvs</p>
<p style="font-family: Simsun; line-height: normal; font-size: medium;">______________________________________</p>
<p>检查是否存在cvs端口服务，防火墙需要打开2401的权限。</p>
<p>#more /etc/services | grep cvspserver</p>
<p>看看是否有:</p>
<p>cvspserver  2401/tcp #CVS client/server operations</p>
<p>cvspserver  2401/udp #CVS client/server operations</p>
<p style="font-family: Simsun; line-height: normal; font-size: medium;">______________________________________</p>
<p>#vi /etc/xinetd.d/cvspserver</p>
<p>service cvspserver</p>
<p>{</p>
<p>disable = no</p>
<p>flags           = REUSE</p>
<p>socket_type     = stream</p>
<p>wait            = no</p>
<p>user            = root</p>
<p>server          = /usr/bin/cvs</p>
<p>server_args     = -f &#8211;allow-root=/fse/CVS_REP/cvs_docs   &#8211;allow-root=/fse/CVS_REP/cvs_classes pserver</p>
<p>log_on_failure  += USERID</p>
<p>}</p>
<p style="font-family: Simsun; line-height: normal; font-size: medium;">______________________________________</p>
<p>初始化CVS</p>
<p>#su cvsroot</p>
<p>#cvs -d /fse/CVS_REP/cvs_docs init</p>
<p>#cvs -d /fse/CVS_REP/cvs_classes init</p>
<p style="font-family: Simsun; line-height: normal; font-size: medium;">______________________________________</p>
<p>重启服务</p>
<p>#/etc/init.d/xinetd restart</p>
<p>如果没有 xinetd 可以执行</p>
<p>#yum install xinetd</p>
<p style="font-family: Simsun; line-height: normal; font-size: medium;">______________________________________</p>
<p>检查CVS服务</p>
<p>#netstat -l | grep cvspserver</p>
<p>此处需打开防火墙的 2401 端口    (如果没有开启防火墙，不用做这一步)</p>
<p>vi  /etc/sysconfig/iptables</p>
<p>在后面加</p>
<p>-A RH-Firewall-1-INPUT -m state &#8211;state NEW -m tcp -p tcp &#8211;dport 2401 -j ACCEPT</p>
<p>可在windows cmd:<span style="white-space:pre"> </span>telnet 192.168.1.199 2401 检查是否打开</p>
<p style="font-family: Simsun; line-height: normal; font-size: medium;">______________________________________</p>
<p>导入程序</p>
<p>-先进入到网站的根目录下 cd /ROOT/www/docs</p>
<p>cvsroot$ cvs -d /fse/CVS_REP/cvs_docs import -m “new www” docs vendor_tag release_tag</p>
<p style="font-family: Simsun; line-height: normal; font-size: medium;">______________________________________</p>
<p>分配cvs帐号的脚本 adduse</p>
<p>vi /ROOT/CVS_REP/adduser.sh<br />
给予执行权限<br />
chmod +x <span style="font-size: x-small;"> </span><span style="font-family: Simsun; line-height: normal; font-size: small;"> </span></p>
<p style="font-family: Simsun; line-height: normal; font-size: medium; display: inline !important; ">/ROOT/CVS_REP/adduser.sh</p>
<p style="font-family: Simsun; line-height: normal; font-size: medium; display: inline !important; ">
<p style="font-family: Simsun; line-height: normal; font-size: medium; display: inline !important; ">
<p>以下是文件内容 (”exp,“后面是执行范例，需要在 /ROOT/CVS_REP/文件夹下执行)</p>
<p>#!/usr/bin/perl</p>
<p># Simple script to take a username and password and</p>
<p># return a line suitable for pasting into the CVS</p>
<p># password file</p>
<p>// 添加用户</p>
<p># exp: ./adduser.sh wangcy 123456 cvsroot &gt;&gt; cvs_other/CVSROOT/passwd</p>
<p>($u,$p,$g)=@ARGV;</p>
<p>@d=(A..Z,a..z);</p>
<p>$s=$d[rand(52)].$d[rand52];</p>
<p>print $u.”:”.crypt($p,$s).”:”.$g.”\n”;</p>
<p style="font-family: Simsun; line-height: normal; font-size: medium;">______________________________________</p>
<p>提交cvs的同时发布新的代码到docs目录中</p>
<p>#vi cvs_other/CVSROOT/loginfo 最后一行增加</p>
<p>docs /fse/CVS_REP/cvs_docs/CVSROOT/log.in %s -f /fse/CVS_REP/cvs_docs/CVSROOT/commitlog  -a /fse/docs</p>
<p>log.in文件内容及说明详见<br />
<a href=" http://www.wangchao123.com/2011/12/05/747"> http://www.wangchao123.com/2011/12/05/747</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/12/05/746/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CVS 实时同步到真实代码 实时发布 (转)  附: log.in 及 log_php.pl 文件下载，任选一个即可</title>
		<link>http://www.wangchao123.com/2011/12/05/747</link>
		<comments>http://www.wangchao123.com/2011/12/05/747#comments</comments>
		<pubDate>Mon, 05 Dec 2011 09:50:34 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[开发工具软件]]></category>
		<category><![CDATA[服务器 网络]]></category>
		<category><![CDATA[cvs]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=747</guid>
		<description><![CDATA[文章转自 http://www.cnblogs.com/oxo/articles/472518.html 文件下载 /home/cvsroot/test/CVSROOT/loginfo 文件用于控制仓库中版本变更和目录添加之后，log 信息发送到哪里的控制。 loginfo相当于是一个事件驱动器，只要提交了新的版本到cvs中就会触发里面的程序。 loginfo 文件有一个标准的脚本 hook 形式(参阅 Trigger Scripts)，每一行是一个正则表达式和所执行的命令。它支持 ALL 和 DEFAULT 关键字。 调用任何指定的脚本: commit 每个目录一次，在此目录中的所有文件成功提交之后立即执行。 import 每个 import 一次，完成所有写操作之后立即执行。 add 成功 add 到目录之后立即执行。 通过 loginfo 调用的任何脚本会从标准输入获得 log 信息。注意过滤程序 必须 从标准输入读 所有 的 log 信息，否则 cvs 将因管道信号打断而失败。 除了通用格式化字符串以外(参阅 syntax)，loginfo 还支持: {stVv} 文件属性，其中: s    文件名 T    目标的标签名，或者在没有相关标签的时候为空字串(通常是主干) V    旧版本号(提交前) v    新版本号(提交后) 例如，有效的格式化字符串是 [...]]]></description>
			<content:encoded><![CDATA[<p>文章转自</p>
<p style="font-family: Simsun; line-height: normal; font-size: medium;">http://www.cnblogs.com/oxo/articles/472518.html</p>
<p><a href="/file.rar">文件下载</a></p>
<div style="width:400px">
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tbody>
<tr>
<td style="font-size: 12px; color: #303030; font-family: Verdana, Helvetica, Arial; word-break: break-all; line-height: 18px;" valign="top">
<table style="border: 1px dashed #cccccc;" border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td style="font-size: 12px; color: #303030; font-family: Verdana, Helvetica, Arial; word-break: break-all; line-height: 18px;">
<div style="font-size: 12px; text-align: justify; word-break: break-all;">
<div style="background-color: white; color: #4b4b4b; padding: 10px; border: 1px dotted #000000;">
<div style="margin-top: 10px;  font-size: 12px; color: #303030; background-repeat: no-repeat no-repeat;">
<div id="cnblogs_post_body">
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">/home/cvsroot/test/CVSROOT/loginfo 文件用于控制仓库中版本变更和目录添加之后，log 信息发送到哪里的控制。 loginfo相当于是一个事件驱动器，只要提交了新的版本到cvs中就会触发里面的程序。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">loginfo 文件有一个标准的脚本 hook 形式(参阅 Trigger Scripts)，每一行是一个正则表达式和所执行的命令。它支持 ALL 和 DEFAULT 关键字。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">调用任何指定的脚本:</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">commit<br />
每个目录一次，在此目录中的所有文件成功提交之后立即执行。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">import<br />
每个 import 一次，完成所有写操作之后立即执行。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">add<br />
成功 add 到目录之后立即执行。<br />
通过 loginfo 调用的任何脚本会从标准输入获得 log 信息。注意过滤程序 必须 从标准输入读 所有 的 log 信息，否则 cvs 将因管道信号打断而失败。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">除了通用格式化字符串以外(参阅 syntax)，loginfo 还支持:</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">{stVv}<br />
文件属性，其中:<br />
s    文件名</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">T    目标的标签名，或者在没有相关标签的时候为空字串(通常是主干)</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">V    旧版本号(提交前)</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">v    新版本号(提交后)<br />
例如，有效的格式化字符串是 `%%&#8217;, `%s&#8217;, `%{s}&#8217; 和 `%{stVv}&#8217;。</p>
<p>我们了解了loginfo的功能以后就知道我要做什么，我们将提交到cvs里面的版本能不能直接发行，这样岂不是很方便。下面这个程序就解决了这样的问题。原来程序只是作为版本修改通知，现在我改进以后同时支持发布了。</p>
<div style="padding-right: 5px; padding-left: 4px; font-size: 13px; padding-bottom: 4px; width: 600px; word-break: break-all; padding-top: 4px; background-color: #eeeeee; border: 1px solid #cccccc;"><img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><span style="color: #000000;">#! </span><span style="color: #000000;">/</span><span style="color: #000000;">usr</span><span style="color: #000000;">/</span><span style="color: #000000;">bin</span><span style="color: #000000;">/</span><span style="color: #000000;">perl<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># </span><span style="color: #000000;">-*-</span><span style="color: #000000;">Perl</span><span style="color: #000000;">-*-</span><span style="color: #000000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># Usage: </span><span style="color: #0000ff;">log</span><span style="color: #000000;">.pl [</span><span style="color: #000000;">-</span><span style="color: #000000;">u user] [[</span><span style="color: #000000;">-</span><span style="color: #000000;">m mailto] ] [</span><span style="color: #000000;">-</span><span style="color: #000000;">s] [</span><span style="color: #000000;">-</span><span style="color: #000000;">V] </span><span style="color: #000000;">-</span><span style="color: #000000;">a </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">execution dir&#8217; -f logfile &#8217;dirname file &#8217;</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># </span><span style="color: #000000;">-</span><span style="color: #000000;">u user </span><span style="color: #000000;">-</span><span style="color: #000000;"> $USER passed from loginfo<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># </span><span style="color: #000000;">-</span><span style="color: #000000;">m mailto </span><span style="color: #000000;">-</span><span style="color: #000000;"> </span><span style="color: #0000ff;">for</span><span style="color: #000000;"> </span><span style="color: #0000ff;">each</span><span style="color: #000000;"> user </span><span style="color: #0000ff;">to</span><span style="color: #000000;"> receive cvs </span><span style="color: #0000ff;">log</span><span style="color: #000000;"> reports<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#                       (multiple </span><span style="color: #000000;">-</span><span style="color: #000000;">m</span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">s permitted)</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"># </span><span style="color: #000000;">-</span><span style="color: #000000;">s </span><span style="color: #000000;">-</span><span style="color: #000000;"> </span><span style="color: #0000ff;">to</span><span style="color: #000000;"> prevent </span><span style="color: #000000;">“</span><span style="color: #000000;">cvs status -v</span><span style="color: #000000;">“</span><span style="color: #000000;"> messages<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># </span><span style="color: #000000;">-</span><span style="color: #000000;">V </span><span style="color: #000000;">-</span><span style="color: #000000;"> without </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">-s&#8217;, don&#8217;t pass &#8217;-v&#8217; to cvs status</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"># </span><span style="color: #000000;">-</span><span style="color: #000000;">a dirname </span><span style="color: #000000;">-</span><span style="color: #000000;"> </span><span style="color: #0000ff;">to</span><span style="color: #000000;"> specify actual execution directory<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># </span><span style="color: #000000;">-</span><span style="color: #000000;">f logfile </span><span style="color: #000000;">-</span><span style="color: #000000;"> </span><span style="color: #0000ff;">for</span><span style="color: #000000;"> the logfile </span><span style="color: #0000ff;">to</span><span style="color: #000000;"> append </span><span style="color: #0000ff;">to</span><span style="color: #000000;"> (mandatory,<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#                       but only one logfile can be specified).<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />use strict;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />use IO::File;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $cvsroot </span><span style="color: #000000;">=</span><span style="color: #000000;"> $ENV{</span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">CVSROOT&#8217;};</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># turn off setgid<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />$) </span><span style="color: #000000;">=</span><span style="color: #000000;"> $(;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $dostatus </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $verbosestatus </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $users;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $login;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $donefiles;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $logfile;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $activedir;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my @files;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># parse command line arguments<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #0000ff;">while</span><span style="color: #000000;"> (@ARGV) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> my $arg </span><span style="color: #000000;">=</span><span style="color: #000000;"> shift @ARGV;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($arg eq </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">-m&#8217;) {</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"> $users </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">“</span><span style="color: #000000;">$users </span><span style="color: #000000;">“</span><span style="color: #000000;"> . shift @ARGV;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> } elsif ($arg eq </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">-u&#8217;) {</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"> $login </span><span style="color: #000000;">=</span><span style="color: #000000;"> shift @ARGV;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> } elsif ($arg eq </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">-f&#8217;) {</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"> ($logfile) </span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;"> die </span><span style="color: #000000;">“</span><span style="color: #000000;">Too many &#8217;-f&#8217; args</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $logfile </span><span style="color: #000000;">=</span><span style="color: #000000;"> shift @ARGV;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> } elsif ($arg eq </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">-a&#8217;) {</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"> $activedir </span><span style="color: #000000;">=</span><span style="color: #000000;"> shift @ARGV;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> } elsif ($arg eq </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">-s&#8217;) {</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"> $dostatus </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> } elsif ($arg eq </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">-V&#8217;) {</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"> $verbosestatus </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> ($donefiles) </span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;"> die </span><span style="color: #000000;">“</span><span style="color: #000000;">Too many arguments!\n</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $donefiles </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> @files </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">split</span><span style="color: #000000;">(</span><span style="color: #000000;">/</span><span style="color: #000000;"> </span><span style="color: #000000;">/</span><span style="color: #000000;">, $arg);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />}<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># the first argument </span><span style="color: #0000ff;">is</span><span style="color: #000000;"> the module location relative </span><span style="color: #0000ff;">to</span><span style="color: #000000;"> $CVSROOT<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $modulepath </span><span style="color: #000000;">=</span><span style="color: #000000;"> shift @files;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $mailcmd </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">“</span><span style="color: #000000;">| Mail -s &#8217;CVS update: $modulepath&#8217;</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># Initialise some </span><span style="color: #0000ff;">date</span><span style="color: #000000;"> </span><span style="color: #0000ff;">and</span><span style="color: #000000;"> </span><span style="color: #0000ff;">time</span><span style="color: #000000;"> arrays<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my @mos </span><span style="color: #000000;">=</span><span style="color: #000000;"> (</span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">January&#8217;,'February&#8217;,'March&#8217;,'April&#8217;,'May&#8217;,'June&#8217;,'July&#8217;,</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"> </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">August&#8217;,'September&#8217;,'October&#8217;,'November&#8217;,'December&#8217;);</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">my @days </span><span style="color: #000000;">=</span><span style="color: #000000;"> (</span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">Sunday&#8217;,'Monday&#8217;,'Tuesday&#8217;,'Wednesday&#8217;,'Thursday&#8217;,'Friday&#8217;,'Saturday&#8217;);</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my ($sec,$min,$</span><span style="color: #0000ff;">hour</span><span style="color: #000000;">,$mday,$mon,$</span><span style="color: #0000ff;">year</span><span style="color: #000000;">,$wday,$yday,$isdst) </span><span style="color: #000000;">=</span><span style="color: #000000;"> localtime;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />$</span><span style="color: #0000ff;">year</span><span style="color: #000000;"> </span><span style="color: #000000;">+=</span><span style="color: #000000;"> </span><span style="color: #000000;">1900</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># </span><span style="color: #0000ff;">get</span><span style="color: #000000;"> a login name </span><span style="color: #0000ff;">for</span><span style="color: #000000;"> the guy doing the commit.<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($login eq </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">&#8216;) {</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"> $login </span><span style="color: #000000;">=</span><span style="color: #000000;"> getlogin || (getpwuid($</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">))[</span><span style="color: #000000;">0</span><span style="color: #000000;">] || </span><span style="color: #000000;">“</span><span style="color: #000000;">nobody</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />}<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># open </span><span style="color: #0000ff;">log</span><span style="color: #000000;"> file </span><span style="color: #0000ff;">for</span><span style="color: #000000;"> appending<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $logfh </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> IO::File </span><span style="color: #000000;">“</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;">“</span><span style="color: #000000;"> . $logfile<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">or</span><span style="color: #000000;"> die </span><span style="color: #000000;">“</span><span style="color: #000000;">Could not open(</span><span style="color: #000000;">“</span><span style="color: #000000;"> . $logfile . </span><span style="color: #000000;">“</span><span style="color: #000000;">): $!\n</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># send mail, </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> there</span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">s anyone to send to!</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $mailfh;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($users) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $mailcmd </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">“</span><span style="color: #000000;">$mailcmd $users</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $mailfh </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> IO::File $mailcmd<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">or</span><span style="color: #000000;"> die </span><span style="color: #000000;">“</span><span style="color: #000000;">Could not Exec($mailcmd): $!\n</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />}<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># print out the </span><span style="color: #0000ff;">log</span><span style="color: #000000;"> Header<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />$logfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">\n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />$logfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">****************************************\n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />$logfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">Date:\t$days[$wday] $mos[$mon] $mday, $year @ $hour:</span><span style="color: #000000;">“</span><span style="color: #000000;"> . sprintf(</span><span style="color: #000000;">“</span><span style="color: #000000;">%02d</span><span style="color: #000000;">“</span><span style="color: #000000;">, $min) . </span><span style="color: #000000;">“</span><span style="color: #000000;">\n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />$logfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">Author:\t$login\n\n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($mailfh) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $mailfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">\n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $mailfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">Date:\t$days[$wday] $mos[$mon] $mday, $year @ $hour:</span><span style="color: #000000;">“</span><span style="color: #000000;"> . sprintf(</span><span style="color: #000000;">“</span><span style="color: #000000;">%02d</span><span style="color: #000000;">“</span><span style="color: #000000;">, $min) . </span><span style="color: #000000;">“</span><span style="color: #000000;">\n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $mailfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">Author:\t$login\n\n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />}<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># print the stuff from logmsg that comes in </span><span style="color: #0000ff;">on</span><span style="color: #000000;"> stdin </span><span style="color: #0000ff;">to</span><span style="color: #000000;"> the logfile<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $infh </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> IO::File </span><span style="color: #000000;">“</span><span style="color: #000000;">&lt; -</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $cno </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $cdir;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />foreach ($infh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">getlines) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $logfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> #print(</span><span style="color: #000000;">“</span><span style="color: #000000;">cc-&gt; $_</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;">($cno </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">){<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> my $ff </span><span style="color: #000000;">=</span><span style="color: #000000;"> $_;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> my @nw </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">split</span><span style="color: #000000;"> (</span><span style="color: #000000;">/</span><span style="color: #000000;">:</span><span style="color: #000000;">/</span><span style="color: #000000;">, $ff) ;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $cdir </span><span style="color: #000000;">=</span><span style="color: #000000;"> @nw[</span><span style="color: #000000;">1</span><span style="color: #000000;">];<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($mailfh) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $mailfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">$_</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $cno</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />}<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />undef $infh;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />$logfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">\n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#print(</span><span style="color: #000000;">“</span><span style="color: #000000;">cdir=$cdir</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $adir </span><span style="color: #000000;">=</span><span style="color: #000000;"> substr $cdir, </span><span style="color: #000000;">0</span><span style="color: #000000;">, length($cdir) </span><span style="color: #000000;">-</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />#my $asubdir </span><span style="color: #000000;">=</span><span style="color: #000000;"> substr $cdir, </span><span style="color: #000000;">18</span><span style="color: #000000;"> ;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $asubdir </span><span style="color: #000000;">=</span><span style="color: #000000;"> substr ($cdir, index($cdir,</span><span style="color: #000000;">“</span><span style="color: #000000;">/</span><span style="color: #000000;">“</span><span style="color: #000000;">,</span><span style="color: #000000;">5</span><span style="color: #000000;">) </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">) ;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />chomp $asubdir;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $ain </span><span style="color: #000000;">=</span><span style="color: #000000;"> index($modulepath,</span><span style="color: #000000;">“</span><span style="color: #000000;">/</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />my $mopath_sub </span><span style="color: #000000;">=</span><span style="color: #000000;"> substr ($modulepath, $ain</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /># after </span><span style="color: #0000ff;">log</span><span style="color: #000000;"> information, </span><span style="color: #0000ff;">do</span><span style="color: #000000;"> an </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">cvs -Qq status -v&#8217; on each file in the arguments.</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">#<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($dostatus !</span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">while</span><span style="color: #000000;"> (@files) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> my $file </span><span style="color: #000000;">=</span><span style="color: #000000;"> shift @files;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($file eq </span><span style="color: #000000;">“</span><span style="color: #000000;">-</span><span style="color: #000000;">“</span><span style="color: #000000;">) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $logfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">[input file was '-']\n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($mailfh) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $mailfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print (</span><span style="color: #000000;">“</span><span style="color: #000000;">[input file was '-']\n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> exec </span><span style="color: #000000;">“</span><span style="color: #000000;">mkdir -m 755 $activedir/$mopath_sub</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> #die </span><span style="color: #000000;">“</span><span style="color: #000000;">file transfer for latest version failed: $!</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> last;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> my $rcsfh </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> IO::File;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> my $pid </span><span style="color: #000000;">=</span><span style="color: #000000;"> $rcsfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">open (</span><span style="color: #000000;">“</span><span style="color: #000000;">-|</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ( !defined $pid )<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> die </span><span style="color: #000000;">“</span><span style="color: #000000;">fork failed: $!</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($pid </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">)<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> my @command </span><span style="color: #000000;">=</span><span style="color: #000000;"> (</span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">cvs&#8217;, &#8217;-nQq&#8217;, &#8217;status&#8217;);</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($verbosestatus)<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> push @command, </span><span style="color: #008000;">&#8216;</span><span style="color: #008000;">-v&#8217;;</span><span style="color: #008000;"><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;"> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> push @command, $file;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> exec @command;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> die </span><span style="color: #000000;">“</span><span style="color: #000000;">cvs exec failed: $!</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> my $line;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">while</span><span style="color: #000000;"> ($line </span><span style="color: #000000;">=</span><span style="color: #000000;"> $rcsfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">getline) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $logfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print ($line);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($mailfh) {<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $mailfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">print ($line);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> #print(</span><span style="color: #000000;">“</span><span style="color: #000000;">cp $adir/$file $activedir/$mopath_sub,$asubdir \n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> print (</span><span style="color: #000000;">“</span><span style="color: #000000;">\n  Active Dir : $activedir/$asubdir  \n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(index($asubdir,</span><span style="color: #000000;">“</span><span style="color: #000000;">src/</span><span style="color: #000000;">“</span><span style="color: #000000;">)</span><span style="color: #000000;">==</span><span style="color: #000000;">0</span><span style="color: #000000;">){<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> my $tmp_2</span><span style="color: #000000;">=</span><span style="color: #000000;">substr $asubdir,</span><span style="color: #000000;">4</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $asubdir </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">“</span><span style="color: #000000;">WebRoot/WEB-INF/classes/$tmp_2</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #000000;">-</span><span style="color: #000000;">d </span><span style="color: #000000;">“</span><span style="color: #000000;">$activedir/$asubdir</span><span style="color: #000000;">“</span><span style="color: #000000;">){<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> print(</span><span style="color: #000000;">“</span><span style="color: #000000;">Dir exists:$activedir/$asubdir \n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> exec </span><span style="color: #000000;">“</span><span style="color: #000000;">mkdir -p $activedir/$asubdir</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> print(</span><span style="color: #000000;">“</span><span style="color: #000000;">cp $adir/$file $activedir/$asubdir \n</span><span style="color: #000000;">“</span><span style="color: #000000;">);<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(index($asubdir,</span><span style="color: #000000;">“</span><span style="color: #000000;">/tmp/cvs-</span><span style="color: #000000;">“</span><span style="color: #000000;">)</span><span style="color: #000000;">==</span><span style="color: #000000;">0</span><span style="color: #000000;">){<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> exec </span><span style="color: #000000;">“</span><span style="color: #000000;">cp $adir/$file $activedir</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> exec </span><span style="color: #000000;">“</span><span style="color: #000000;">cp $adir/$file $activedir/$asubdir</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> #die </span><span style="color: #000000;">“</span><span style="color: #000000;">file transfer for latest version failed: $!</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> undef $rcsfh;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> }<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />}<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />$logfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">close()<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> </span><span style="color: #0000ff;">or</span><span style="color: #000000;"> die </span><span style="color: #000000;">“</span><span style="color: #000000;">Write to $logfile failed: $!</span><span style="color: #000000;">“</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($mailfh)<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />{<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> $mailfh</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">close;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /> die </span><span style="color: #000000;">“</span><span style="color: #000000;">Pipe to $mailcmd failed</span><span style="color: #000000;">“</span><span style="color: #000000;"> </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> $?;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />}<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />## must </span><span style="color: #0000ff;">exit</span><span style="color: #000000;"> cleanly<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" />##<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #0000ff;">exit</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br />
<img style="border: 0px initial initial;" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" alt="" align="top" /></span></div>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/12/05/747/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>用 cookie 的方法实现 ie 背景音乐不间断播放，有小断在页面切换的时候</title>
		<link>http://www.wangchao123.com/2011/10/20/742</link>
		<comments>http://www.wangchao123.com/2011/10/20/742#comments</comments>
		<pubDate>Thu, 20 Oct 2011 11:34:23 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/2011/10/20/742</guid>
		<description><![CDATA[&#60;meta http-equiv=”Content-Type” content=”text/html; charset=utf-8&#8243; /&#62; &#60;title&#62;maryma&#60;/title&#62; &#60;script src=”/js/jquery.js” type=”text/javascript”&#62;&#60;/script&#62; &#60;script src=”/js/jquery.jqzoom-core.js” type=”text/javascript”&#62;&#60;/script&#62; &#60;script src=”/js/slides.min.jquery.js” type=”text/javascript”&#62;&#60;/script&#62; &#60;link rel=”stylesheet” href=”/css/jquery.jqzoom.css” type=”text/css”&#62; &#60;link media=”screen” type=”text/css” href=”/css/css.css” rel=”stylesheet”&#62; &#60;script src=”/js/slides.min.jquery.js”&#62;&#60;/script&#62; &#60;link rel=”stylesheet” href=”/css/slides.css”&#62; &#60;script src=”/js/jquery.bxSlider.min.js”&#62;&#60;/script&#62; &#60;link rel=”stylesheet” href=”/css/bx_styles.css”&#62; &#60;script&#62; //写cookies函数 function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值 { var Time = 2; //此 cookie 将被保存分钟 var exp = new Date();    //new Date(“December 31, [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;meta http-equiv=”Content-Type” content=”text/html; charset=utf-8&#8243; /&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;title&gt;maryma&lt;/title&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;script src=”/js/jquery.js” type=”text/javascript”&gt;&lt;/script&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;script src=”/js/jquery.jqzoom-core.js” type=”text/javascript”&gt;&lt;/script&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;script src=”/js/slides.min.jquery.js” type=”text/javascript”&gt;&lt;/script&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;link rel=”stylesheet” href=”/css/jquery.jqzoom.css” type=”text/css”&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;link media=”screen” type=”text/css” href=”/css/css.css” rel=”stylesheet”&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;script src=”/js/slides.min.jquery.js”&gt;&lt;/script&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;link rel=”stylesheet” href=”/css/slides.css”&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;script src=”/js/jquery.bxSlider.min.js”&gt;&lt;/script&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;link rel=”stylesheet” href=”/css/bx_styles.css”&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;script&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">//写cookies函数</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">var Time = 2; //此 cookie 将被保存分钟</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">var exp = new Date();    //new Date(“December 31, 9998&#8243;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">exp.setTime(exp.getTime() + Time*60*1000);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">document.cookie = name + “=”+ escape (value) + “;expires=” + exp.toGMTString();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">function getCookie(name)//取cookies函数</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">var arr = document.cookie.match(new RegExp(“(^| )”+name+”=([^;]*)(;|$)”));</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">if(arr != null) return unescape(arr[2]); return null;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">function delCookie(name)//删除cookie</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">{</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">var exp = new Date();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">exp.setTime(exp.getTime() &#8211; 1);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">var cval=getCookie(name);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">if(cval!=null) document.cookie= name + “=”+cval+”;expires=”+exp.toGMTString();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">//SetCookie (“kingM”, “1&#8243;)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">//alert(getCookie(&#8216;kingM&#8217;));</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">var getking=getCookie(&#8216;kingM&#8217;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">var player = new ActiveXObject(“MediaPlayer.MediaPlayer”);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">var src=”http://t/img/bk.mp3&#8243;;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">function play(){</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>if(player.duration&gt;0){</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> <span style="white-space: pre;"> </span>player.play();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>} else {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>if(getCookie (“time_bging”)){</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> player.CurrentPosition += getCookie(“time_bging”);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>player.Open(src);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">function stop(){</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">player.Stop();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">function pause(){</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">player.Pause();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">if(getking == “1&#8243;){</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>play();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>//SetCookie (“kingM”, “1&#8243;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">};</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">//delCookie(“kingM”);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;/script&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;!&#8211;&lt;bgsound src=”http://t/img/bk.mp3&#8243; loop=”-1&#8243; id=”soundctl”&gt;&#8211;&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;script type=”text/javascript”&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>$(function(){</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>$(“.sound_box”).click(function(){</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>if(getCookie(&#8216;kingM&#8217;) == 1)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> $(“.sound_box”).css(“background”,”url(/img/sound.jpg) bottom no-repeat”);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> SetCookie (“kingM”, “0&#8243;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> player.pause();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> }</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>else</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>$(“.sound_box”).css(“background”,”url(/img/sound.jpg) top no-repeat”);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>SetCookie (“kingM”, “1&#8243;);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>play();</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>//player.paly(); 已经开始播放的时候用这个</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> }</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>});</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>if (getCookie(&#8216;kingM&#8217;) != 1) {<span style="white-space: pre;"> </span>//格式化按钮</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>$(“.sound_box”).css(“background”,”url(img/sound.jpg) bottom no-repeat”);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>}</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>//离开页面时保存当前播放进度</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> window.onbeforeunload = function() {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> <span style="white-space: pre;"> </span>SetCookie (“time_bging”, player.CurrentPosition);</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> }</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>})</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;/script&gt;</div>
<p>&lt;meta http-equiv=”Content-Type” content=”text/html; charset=utf-8&#8243; /&gt;</p>
<p>&lt;title&gt;maryma&lt;/title&gt;</p>
<p>&lt;script src=”/js/jquery.js” type=”text/javascript”&gt;&lt;/script&gt;</p>
<p>&lt;script src=”/js/jquery.jqzoom-core.js” type=”text/javascript”&gt;&lt;/script&gt;</p>
<p>&lt;script src=”/js/slides.min.jquery.js” type=”text/javascript”&gt;&lt;/script&gt;</p>
<p>&lt;link rel=”stylesheet” href=”/css/jquery.jqzoom.css” type=”text/css”&gt;</p>
<p>&lt;link media=”screen” type=”text/css” href=”/css/css.css” rel=”stylesheet”&gt;</p>
<p>&lt;script src=”/js/slides.min.jquery.js”&gt;&lt;/script&gt;</p>
<p>&lt;link rel=”stylesheet” href=”/css/slides.css”&gt;</p>
<p>&lt;script src=”/js/jquery.bxSlider.min.js”&gt;&lt;/script&gt;</p>
<p>&lt;link rel=”stylesheet” href=”/css/bx_styles.css”&gt;</p>
<p>&lt;script&gt;</p>
<p>//写cookies函数</p>
<p>function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值</p>
<p>{</p>
<p>var Time = 2; //此 cookie 将被保存分钟</p>
<p>var exp = new Date();    //new Date(“December 31, 9998&#8243;);</p>
<p>exp.setTime(exp.getTime() + Time*60*1000);</p>
<p>document.cookie = name + “=”+ escape (value) + “;expires=” + exp.toGMTString();</p>
<p>}</p>
<p>function getCookie(name)//取cookies函数</p>
<p>{</p>
<p>var arr = document.cookie.match(new RegExp(“(^| )”+name+”=([^;]*)(;|$)”));</p>
<p>if(arr != null) return unescape(arr[2]); return null;</p>
<p>}</p>
<p>function delCookie(name)//删除cookie</p>
<p>{</p>
<p>var exp = new Date();</p>
<p>exp.setTime(exp.getTime() &#8211; 1);</p>
<p>var cval=getCookie(name);</p>
<p>if(cval!=null) document.cookie= name + “=”+cval+”;expires=”+exp.toGMTString();</p>
<p>}</p>
<p>//SetCookie (“kingM”, “1&#8243;)</p>
<p>//alert(getCookie(&#8216;kingM&#8217;));</p>
<p>var getking=getCookie(&#8216;kingM&#8217;);</p>
<p>var player = new ActiveXObject(“MediaPlayer.MediaPlayer”);</p>
<p>var src=”http://t/img/bk.mp3&#8243;;</p>
<p>function play(){</p>
<p><span style="white-space: pre;"> </span>if(player.duration&gt;0){</p>
<p><span style="white-space: pre;"> </span> <span style="white-space: pre;"> </span>player.play();</p>
<p><span style="white-space: pre;"> </span>} else {</p>
<p><span style="white-space: pre;"> </span>if(getCookie (“time_bging”)){</p>
<p><span style="white-space: pre;"> </span> player.CurrentPosition += getCookie(“time_bging”);</p>
<p><span style="white-space: pre;"> </span>}</p>
<p><span style="white-space: pre;"> </span>player.Open(src);</p>
<p><span style="white-space: pre;"> </span>}</p>
<p>}</p>
<p>function stop(){</p>
<p>player.Stop();</p>
<p>}</p>
<p>function pause(){</p>
<p>player.Pause();</p>
<p>}</p>
<p>if(getking == “1&#8243;){</p>
<p><span style="white-space: pre;"> </span>play();</p>
<p><span style="white-space: pre;"> </span></p>
<p><span style="white-space: pre;"> </span>//SetCookie (“kingM”, “1&#8243;);</p>
<p>};</p>
<p>//delCookie(“kingM”);</p>
<p>&lt;/script&gt;</p>
<p>&lt;!&#8211;&lt;bgsound src=”http://t/img/bk.mp3&#8243; loop=”-1&#8243; id=”soundctl”&gt;&#8211;&gt;</p>
<p>&lt;script type=”text/javascript”&gt;</p>
<p><span style="white-space: pre;"> </span>$(function(){</p>
<p><span style="white-space: pre;"> </span>$(“.sound_box”).click(function(){</p>
<p><span style="white-space: pre;"> </span>if(getCookie(&#8216;kingM&#8217;) == 1)</p>
<p><span style="white-space: pre;"> </span> {</p>
<p><span style="white-space: pre;"> </span> $(“.sound_box”).css(“background”,”url(/img/sound.jpg) bottom no-repeat”);</p>
<p><span style="white-space: pre;"> </span> SetCookie (“kingM”, “0&#8243;);</p>
<p><span style="white-space: pre;"> </span> player.pause();</p>
<p><span style="white-space: pre;"> </span> }</p>
<p><span style="white-space: pre;"> </span>else</p>
<p><span style="white-space: pre;"> </span> {</p>
<p><span style="white-space: pre;"> </span>$(“.sound_box”).css(“background”,”url(/img/sound.jpg) top no-repeat”);</p>
<p><span style="white-space: pre;"> </span>SetCookie (“kingM”, “1&#8243;);</p>
<p><span style="white-space: pre;"> </span>play();</p>
<p><span style="white-space: pre;"> </span>//player.paly(); 已经开始播放的时候用这个</p>
<p><span style="white-space: pre;"> </span> }</p>
<p><span style="white-space: pre;"> </span>});</p>
<p><span style="white-space: pre;"> </span></p>
<p><span style="white-space: pre;"> </span>if (getCookie(&#8216;kingM&#8217;) != 1) {<span style="white-space: pre;"> </span>//格式化按钮</p>
<p><span style="white-space: pre;"> </span>$(“.sound_box”).css(“background”,”url(img/sound.jpg) bottom no-repeat”);</p>
<p><span style="white-space: pre;"> </span>}</p>
<p><span style="white-space: pre;"> </span></p>
<p><span style="white-space: pre;"> </span>//离开页面时保存当前播放进度</p>
<p><span style="white-space: pre;"> </span> window.onbeforeunload = function() {</p>
<p><span style="white-space: pre;"> </span> <span style="white-space: pre;"> </span>SetCookie (“time_bging”, player.CurrentPosition);</p>
<p><span style="white-space: pre;"> </span> }</p>
<p><span style="white-space: pre;"> </span>})</p>
<p>&lt;/script&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/10/20/742/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>密码保护：房子</title>
		<link>http://www.wangchao123.com/2011/10/10/723</link>
		<comments>http://www.wangchao123.com/2011/10/10/723#comments</comments>
		<pubDate>Mon, 10 Oct 2011 02:56:12 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=723</guid>
		<description><![CDATA[无法提供摘要。这是一篇受保护的文章。]]></description>
			<content:encoded><![CDATA[<form action="http://www.wangchao123.com/wp-pass.php" method="post">
<p>这是一篇受密码保护的文章。您需要提供访问密码：</p>
<p><label for="pwbox-723">密码：<br />
<input name="post_password" id="pwbox-723" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="提交" /></p></form>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/10/10/723/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mongoDB windows安装 (转)</title>
		<link>http://www.wangchao123.com/2011/09/07/719</link>
		<comments>http://www.wangchao123.com/2011/09/07/719#comments</comments>
		<pubDate>Wed, 07 Sep 2011 05:56:47 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[数据库 DB]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=719</guid>
		<description><![CDATA[原文地址: http://www.cnblogs.com/lios/archive/2010/11/14/mongoDB.html 1:下载http://www.mongodb.org/display/DOCS/Downloads 选择你要下载的版本 (我下载的是1.6.3版本 Windows 32bit) &#62; 解压软件包，你会看到解压后的文件夹中有个BIN目录，进去之后会看到很多.exe可执行文件，只用关注两个即可(mongod.exe,mongo.exe) mongod.exe //mongodb的服务器端，运行该执行文件可以设置mongodb的端口号，数据文件存储目录等 mongo.exe   //mongodb的客户端，用来连接mongodb并进行相关数据的查询 2.部署，假如我压缩包解压的位置为 d:\program files\mongodb\ &#62; 创建一个存放数据库文件的文件夹 我是放到E盘data文件夹，路径e:\data 设置存放数据库文件的路径 进入 cmd 提示符控制台 cd d:\program files\mongodb\bin&#62; mongod.exe &#8211;dbpath e:\data (这个cmd不要关了！) 3：新打开一个CMD输入：cd d:\mongodb\bin&#62;mongo.exe，如果出现下面提示，恭喜你安装成功了，很简单吧 D:\mongodb\bin&#62;d:\mongodb\bin\mongo.exe MongoDB shell version: 1.6.3 connecting to: test 4：测试 &#62; use test switched to db test &#62; db.foo.save({hello:1,word:2}) &#62; db.foo.find() { "_id" : [...]]]></description>
			<content:encoded><![CDATA[<div style="border: 2px solid #dcdcdc;">
<div style="padding-right: 10px; padding-left: 3px; font-size: 13px; padding-bottom: 5px; padding-top: 10px; line-height: 1.5; margin-left: 5px;">
<div id="cnblogs_post_body">
<div id="blog_text">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">原文地址: <a href="http://www.cnblogs.com/lios/archive/2010/11/14/mongoDB.html">http://www.cnblogs.com/lios/archive/2010/11/14/mongoDB.html</a></p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">1:下载<a style="color: navy; text-decoration: none;" href="http://www.mongodb.org/display/DOCS/Downloads">http://www.mongodb.org/display/DOCS/Downloads</a> 选择你要下载的版本</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">(我下载的是1.6.3版本 Windows 32bit)</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">&gt; 解压软件包，你会看到解压后的文件夹中有个BIN目录，进去之后会看到很多.exe可执行文件，只用关注两个即可(mongod.exe,mongo.exe)</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">mongod.exe //mongodb的服务器端，运行该执行文件可以设置mongodb的端口号，数据文件存储目录等</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">mongo.exe   //mongodb的客户端，用来连接mongodb并进行相关数据的查询</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">2.部署，假如我压缩包解压的位置为 d:\program files\mongodb\</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">&gt; 创建一个存放数据库文件的文件夹 我是放到E盘data文件夹，路径e:\data</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">设置存放数据库文件的路径</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">进入 cmd 提示符控制台</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><span style="line-height: 1.5; color: #808080;"> cd d:\program files\mongodb\bin&gt;</span></p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><span style="line-height: 1.5; color: #808080;"> mongod.exe &#8211;dbpath e:\data</span></p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">(这个cmd不要关了！)</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">3：新打开一个CMD输入：cd d:\mongodb\bin&gt;mongo.exe，如果出现下面提示，恭喜你安装成功了，很简单吧</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; word-break: break-all; overflow-x: auto; overflow-y: auto; padding: 5px; border: 1px solid #cccccc;">
<pre style="margin-top: 0px; margin-bottom: 0px;">
<div><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">D:\mongodb\bin</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">&gt;</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">d:\mongodb\bin\mongo.exe
MongoDB shell version: </span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">1.6</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">.</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">3</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">
connecting to: test</span></div>
</pre>
</div>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">4：测试</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; word-break: break-all; overflow-x: auto; overflow-y: auto; padding: 5px; border: 1px solid #cccccc;">
<pre style="margin-top: 0px; margin-bottom: 0px;">
<div><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;"><span style="line-height: 1.5; font-family: 'Courier New'; background-color: #f5f5f5;"><span style="line-height: 1.5; font-family: 'Courier New'; background-color: #f5f5f5;">&gt; use test
switched to db test
&gt; db.foo.save({hello:1,word:2})
&gt; db.foo.find()
{ "_id" : ObjectId("4cdf992b7579000000003b3e"), "hello" : 1, "word" : 2 }
</span></span></span></div>
</pre>
</div>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">5：退出测试</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; word-break: break-all; overflow-x: auto; overflow-y: auto; padding: 5px; border: 1px solid #cccccc;">
<pre style="margin-top: 0px; margin-bottom: 0px;">
<div><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">&gt; exit (输入exit退出)
<div><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;"><span style="line-height: 1.5; font-family: 'Courier New'; background-color: #f5f5f5;">bye (提示)</span></span></div>

</span></div>
</pre>
</div>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">6：为了平时使用方便，把mongod注册为系统服务，免得以后麻烦，每次要启动</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; word-break: break-all; overflow-x: auto; overflow-y: auto; padding: 5px; border: 1px solid #cccccc;">
<pre style="margin-top: 0px; margin-bottom: 0px;">
<div><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">d:\Program Files\mongodb\bin</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">&gt;</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">mongod.exe </span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">--</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">logpath d:\data </span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">--</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">install
all output going to: d:\data
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via 'net start </span><span style="line-height: 1.5; font-family: 'Courier New'; color: #800000;">"</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #800000;">MongoDB</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #800000;">"</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">'.</span></div>
</pre>
</div>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.5;">7：或者可以编辑批处理文件，每次需要用的时候执行一下。并不关闭命令行窗口</p>
<p style="font-size: 13px; line-height: 1.5;">
<div id="_mcePaste" style="font-size: 13px; line-height: 1.5; position: absolute; left: -10000px; top: 1140px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@echo off</div>
<div id="_mcePaste" style="font-size: 13px; line-height: 1.5; position: absolute; left: -10000px; top: 1140px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">d:\mongodb_bin\bin\mongod.exe &#8211;dbpath d:\mongodb_data</div>
<div id="_mcePaste" style="font-size: 13px; line-height: 1.5; position: absolute; left: -10000px; top: 1140px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">#exitd</div>
<div id="blog_text" style="font-size: 13px; line-height: 1.5;">@echo off</div>
<div id="blog_text">d:\Program Files\mongodb\bin\mongod.exe &#8211;dbpath d:\data</div>
<div id="blog_text" style="font-size: 13px; line-height: 1.5;">#exitd</div>
<p style="font-size: 13px; line-height: 1.5;">
<p style="font-size: 13px; line-height: 1.5;">mongo 此时即可进行客户端与mongodb的连接了，成功后将自动连接mongodb的test库，如果你想连接指定的库，那就使用命令：mongo 数据库名称，如果你将mongodb部署在服务器上，那就使用命令：mongo 服务器IP/数据库名称，此处是”/”，而非”\”，用错了就无法连接成功。</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">讲完部署，接下来讲讲它的性能如何，mongodb的数据写入与数据读取速度是关系性数据库的很多倍以上，具体多少倍可以去看看老赵的空间，他有进行相关的测试，MONGODB现在已经被国内很多网站用来记录网站的日志。MONGODB也属于内存数据库，它会自动将一些数据缓存到内存中，这个我想也是大家平时自己会去做的事情，毕竟占内存总比占CPU好，MONGODB支持分布式部署，这样我们可以分多台服务器来进行部署。注：MONGODB不建议部署在windows 32的机器上，当数据超过2G的时候会出问题，官方建议安装在windows 64位或linux上。（随着microsoft在全球范围内打击盗版的力度越来越大，加之国外的开源软件都慢慢的转向LINUX平台，我们这些跟着微软走的people也该学着跨跨平台了，为了大家今后更好的发展，可以自学一下python或者是ruby）</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">讲完性能，接下来讲讲它的应用环境，MONGODB有好处，那么自然也有它不足的地方，相对于关系性数据库来说，它的安全性就大打折扣了，所以我们应该有选择性的使用，譬如网站的日志记录，网站访问统计等可以使用MONGODB来进行数据存储。</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">讲完应用，接下来讲讲它的语法:</p>
<p style="font-size: 13px; line-height: 1.4; margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<div style="background-color: #f5f5f5; font-family: 'Courier New'; font-size: 13px; word-break: break-all; overflow-x: auto; overflow-y: auto; padding: 5px; border: 1px solid #cccccc;">
<pre style="margin-top: 0px; margin-bottom: 0px;">
<div style="font-family: 'Courier New'; font-size: 13px; line-height: 1.5;"><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">sql: select </span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">*</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;"> from t_user

mongodb: db.t_user.find()

sql: select count(</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">*</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">) from t_user

mongodb: db.t_user.find().count()

sql: select top </span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">10</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;"> </span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">*</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;"> from t_user where id &lt; (select min(id) from (select top </span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">10</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;"> id from t_user order by id desc)) order by id desc </span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">//</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">分页取第11条到第20条的数据

mongodb: db.t_user.find().limit(</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">10</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">).skip(</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">10</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">).sort({})

sql: update t_user set username</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">=</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">'lucky' where id</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">=</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">1</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">

mongodb: db.t_user.update({id:</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">1</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">},{username:</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #800000;">"</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #800000;">lucky</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #800000;">"</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">})

sql: delete t_user where id</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">=</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">1</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">

mongodb: db.t_user.delete({id:</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">1</span><span style="line-height: 1.5; font-family: 'Courier New'; color: #000000;">})

......
</span></div>

<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: x-small;"><span style="line-height: 19px; white-space: normal;">
</span></span></pre>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/09/07/719/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>php curl常用的5个例子 (转)</title>
		<link>http://www.wangchao123.com/2011/06/17/715</link>
		<comments>http://www.wangchao123.com/2011/06/17/715#comments</comments>
		<pubDate>Fri, 17 Jun 2011 04:52:31 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=715</guid>
		<description><![CDATA[php curl常用的5个例子(转) 转载请注明 作者:海底苍鹰 地址:http://blog.51yip.com/php/1039.html 我用php ，curl主要是抓取数据，当然我们可以用其他的方法来抓取，比如fsockopen,file_get_contents等。但是只能抓那些能直接访问的页面，如果要抓取有页面访问控制的页面，或者是登录以后的页面就比较困难了。 1，抓取无访问控制文件 查看复制打印? &#60;?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, “http://localhost/mytest/phpinfo.php”); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果把这行注释掉的话，就会直接输出 $result=curl_exec($ch); curl_close($ch); ?&#62; 2，使用代理进行抓取 为什么要使用代理进行抓取呢？以google为例吧，如果去抓google的数据，短时间内抓的很频繁的话，你就抓取不到了。google对你的ip地址做限制这个时候，你可以换代理重新抓。 查看复制打印? &#60;?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, “http://blog.51yip.com”); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt($ch, CURLOPT_PROXY, 125.21.23.6:8080); //url_setopt($ch, CURLOPT_PROXYUSERPWD, &#8217;user:password&#8217;);如果要密码的话，加上这个 $result=curl_exec($ch); curl_close($ch); ?&#62; 3，post数据后，抓取数据 单独说一下数据提交数据，因为用 curl的时候，很多时候会有数据交互的，所以比较重要的。 查看复制打印? &#60;?php $ch = curl_init(); /*在这里需要注意的是，要提交的数据不能是二维数组或者更高 *例如array(&#8216;name&#8217;=&#62;serialize(array(&#8216;tank&#8217;,'zhang&#8217;)),&#8217;sex&#8217;=&#62;1,&#8217;birth&#8217;=&#62;&#8217;20101010&#8242;) *例如array(&#8216;name&#8217;=&#62;array(&#8216;tank&#8217;,'zhang&#8217;),&#8217;sex&#8217;=&#62;1,&#8217;birth&#8217;=&#62;&#8217;20101010&#8242;)这样会报错的*/ $data = array(&#8216;name&#8217; =&#62; &#8216;test&#8217;, &#8216;sex&#8217;=&#62;1,&#8216;birth&#8217;=&#62;&#8217;20101010&#8242;); curl_setopt($ch, CURLOPT_URL, &#8216;http://localhost/mytest/curl/upload.php&#8217;); curl_setopt($ch, CURLOPT_POST, 1); [...]]]></description>
			<content:encoded><![CDATA[<div style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; font: normal normal normal 13px/19px Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-family: 宋体; line-height: normal; font-size: medium; padding: 0.6em; margin: 0px;">
<div id="wrapper">
<div id="page">
<div>
<div id="content">
<div>
<div id="post-1039">
<div>
<h1 style="font-size: 23px; padding-top: 2px; padding-right: 5px; padding-bottom: 2px; padding-left: 5px; outline-width: 0px; outline-style: initial; outline-color: initial; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #6d94bb; display: inline; font: normal normal normal 23px/26px Arial; letter-spacing: -1px; margin: 0px;">php curl常用的5个例子(转)</h1>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p style="font-family: 宋体; line-height: normal; font-size: medium;"><strong style="font-weight: bold;">转载请注明<br />
作者:海底苍鹰<br />
地址:<a style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #000000; padding: 0px; margin: 0px;" href="http://blog.51yip.com/php/1039.html">http://blog.51yip.com/php/1039.html</a></strong></p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;">我用php ，curl主要是抓取数据，当然我们可以用其他的方法来抓取，比如fsockopen,file_get_contents等。但是只能抓那些能直接访问的页面，如果要抓取有页面访问控制的页面，或者是登录以后的页面就比较困难了。</p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;"><span id="more-1039" style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px; margin: 0px;"> </span></p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;"><strong>1，抓取无访问控制文件</strong></p>
<div style="margin-top: 18px; margin-right: 0px; margin-bottom: 18px; margin-left: 0px; padding-top: 1px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e7e5dc; font-family: Consolas, 'Courier New', Courier, mono; width: 794px; overflow-x: auto; overflow-y: auto;">
<div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 45px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin: 0px;">
<div style="padding-top: 3px; padding-right: 8px; padding-bottom: 10px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-style: solid; border-left-color: #6ce26c; margin: 0px;"><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">查看</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">复制</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">打印</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">?</a></div>
</div>
<ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 1px; margin-left: 45px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; list-style-type: decimal; list-style-position: initial; list-style-image: initial; color: #5c5c5c; padding: 0px;">
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">&lt;?php</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">$ch = curl_init();</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_URL, <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“http://localhost/mytest/phpinfo.php”</span>);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_HEADER, false);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #008200; padding: 0px; margin: 0px;">//如果把这行注释掉的话，就会直接输出</span></span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">$result=curl_exec($ch);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_close($ch);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">?&gt;</span></li>
</ol>
</div>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;"><strong>2，使用代理进行抓取</strong></p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 30px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent;"><strong>为什么要使用代理进行抓取呢？以google为例吧，如果去抓google的数据，短时间内抓的很频繁的话，你就抓取不到了。google对你的ip地址做限制这个时候，你可以换代理重新抓。</strong></p>
<div style="margin-top: 18px; margin-right: 0px; margin-bottom: 18px; margin-left: 0px; padding-top: 1px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e7e5dc; font-family: Consolas, 'Courier New', Courier, mono; width: 794px; overflow-x: auto; overflow-y: auto;">
<div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 45px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin: 0px;">
<div style="padding-top: 3px; padding-right: 8px; padding-bottom: 10px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-style: solid; border-left-color: #6ce26c; margin: 0px;"><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">查看</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">复制</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">打印</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">?</a></div>
</div>
<ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 1px; margin-left: 45px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; list-style-type: decimal; list-style-position: initial; list-style-image: initial; color: #5c5c5c; padding: 0px;">
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">&lt;?php</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">$ch = curl_init();</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_URL, <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“http://blog.51yip.com”</span>);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_HEADER, false);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_PROXY, 125.21.23.6:8080);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #008200; padding: 0px; margin: 0px;">//url_setopt($ch, CURLOPT_PROXYUSERPWD, &#8217;user:password&#8217;);如果要密码的话，加上这个</span></span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">$result=curl_exec($ch);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_close($ch);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">?&gt;</span></li>
</ol>
</div>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;"><strong>3，post数据后，抓取数据</strong></p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 30px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent;"><strong>单独说一下数据提交数据，因为用 curl的时候，很多时候会有数据交互的，所以比较重要的。</strong></p>
<div style="margin-top: 18px; margin-right: 0px; margin-bottom: 18px; margin-left: 0px; padding-top: 1px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e7e5dc; font-family: Consolas, 'Courier New', Courier, mono; width: 794px; overflow-x: auto; overflow-y: auto;">
<div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 45px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin: 0px;">
<div style="padding-top: 3px; padding-right: 8px; padding-bottom: 10px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-style: solid; border-left-color: #6ce26c; margin: 0px;"><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">查看</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">复制</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">打印</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">?</a></div>
</div>
<ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 1px; margin-left: 45px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; list-style-type: decimal; list-style-position: initial; list-style-image: initial; color: #5c5c5c; padding: 0px;">
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">&lt;?php</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">$ch = curl_init();</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #008200; padding: 0px; margin: 0px;">/*在这里需要注意的是，要提交的数据不能是二维数组或者更高</span></span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #008200; padding: 0px; margin: 0px;">*例如array(&#8216;name&#8217;=&gt;serialize(array(&#8216;tank&#8217;,'zhang&#8217;)),&#8217;sex&#8217;=&gt;1,&#8217;birth&#8217;=&gt;&#8217;20101010&#8242;)</span></span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #008200; padding: 0px; margin: 0px;">*例如array(&#8216;name&#8217;=&gt;array(&#8216;tank&#8217;,'zhang&#8217;),&#8217;sex&#8217;=&gt;1,&#8217;birth&#8217;=&gt;&#8217;20101010&#8242;)这样会报错的*/</span></span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">$data = <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #006699; font-weight: bold; padding: 0px; margin: 0px;">array</span>(<span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">&#8216;name&#8217;</span> =&gt; <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">&#8216;test&#8217;</span>, <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">&#8216;sex&#8217;</span>=&gt;1,<span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">&#8216;birth&#8217;</span>=&gt;<span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">&#8217;20101010&#8242;</span>);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_URL, <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">&#8216;http://localhost/mytest/curl/upload.php&#8217;</span>);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_POST, 1);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_POSTFIELDS, $data);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_exec($ch);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">?&gt;</span></li>
</ol>
</div>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 30px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent;"><strong>在 <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #800080; padding: 0px; margin: 0px;">upload.php文件中，print_r($_POST);</span></strong><strong>利用curl就能抓取出upload.php输出的内容Array ( [name] =&gt; test [sex] =&gt; 1 [birth] =&gt; 20101010 )</strong></p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;"><strong>4，抓取一些有页面访问控制的页面</strong></p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;"><a style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #000000; padding: 0px; margin: 0px;" href="http://blog.51yip.com/wp-content/uploads/2010/10/apache_auth1.jpg"><img style="margin-top: 11px; margin-right: 3px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; max-width: 100%; clear: left; padding: 0px; border: 0px initial initial;" title="apache_auth1" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/06/125235uCa.jpg" alt="" width="300" height="225" /></a></p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;">以前写过一篇，<strong><a style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #000000; padding: 0px; margin: 0px;" title="页面访问控制的3种方法" href="http://blog.51yip.com/apachenginx/1051.html" target="_self">页面访问控制的3种方法</a></strong>有兴趣的可以看一下。</p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;">如果用上面提到的方法抓的话，会报以下错误</p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;"><strong>You are not authorized to view this page<br />
You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.</strong></p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;">这个时候，我们就要用<strong>CURLOPT_USERPWD</strong>来进行验证了</p>
<div style="margin-top: 18px; margin-right: 0px; margin-bottom: 18px; margin-left: 0px; padding-top: 1px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e7e5dc; font-family: Consolas, 'Courier New', Courier, mono; width: 794px; overflow-x: auto; overflow-y: auto;">
<div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 45px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin: 0px;">
<div style="padding-top: 3px; padding-right: 8px; padding-bottom: 10px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-style: solid; border-left-color: #6ce26c; margin: 0px;"><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">查看</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">复制</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">打印</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">?</a></div>
</div>
<ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 1px; margin-left: 45px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; list-style-type: decimal; list-style-position: initial; list-style-image: initial; color: #5c5c5c; padding: 0px;">
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">&lt;?php</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">$ch = curl_init();</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_URL, <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“http://club-china”</span>);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #008200; padding: 0px; margin: 0px;">/*CURLOPT_USERPWD主要用来破解页面访问控制的</span></span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #008200; padding: 0px; margin: 0px;">*例如平时我们所以htpasswd产生页面控制等。*/</span></span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #008200; padding: 0px; margin: 0px;">//curl_setopt($ch, CURLOPT_USERPWD, &#8217;231144:2091XTAjmd=&#8217;);</span></span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_HTTPGET, 1);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_REFERER, <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“http://club-china”</span>);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt($ch, CURLOPT_HEADER, 0);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">$result=curl_exec($ch);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_close($ch);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">?&gt;</span></li>
</ol>
</div>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;"><strong>5，模拟登录到sina</strong></p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 30px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent;"><strong>我们要抓取数据，可能是登录以后的内容，这个时候我们就要用到curl的模拟登录功能了。</strong></p>
<div style="margin-top: 18px; margin-right: 0px; margin-bottom: 18px; margin-left: 0px; padding-top: 1px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #e7e5dc; font-family: Consolas, 'Courier New', Courier, mono; width: 794px; overflow-x: auto; overflow-y: auto;">
<div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 45px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; margin: 0px;">
<div style="padding-top: 3px; padding-right: 8px; padding-bottom: 10px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; font: normal normal normal 9px/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-style: solid; border-left-color: #6ce26c; margin: 0px;"><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">查看</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">复制</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">打印</a><a style="margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 9px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #a0a0a0; text-decoration: none; padding: 0px;" href="http://blog.51yip.com/php/1039.html#">?</a></div>
</div>
<ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 1px; margin-left: 45px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; list-style-type: decimal; list-style-position: initial; list-style-image: initial; color: #5c5c5c; padding: 0px;">
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">&lt;?php</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #006699; font-weight: bold; padding: 0px; margin: 0px;">function</span> checklogin( $user, $password )</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">{</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #006699; font-weight: bold; padding: 0px; margin: 0px;">if</span> ( empty<span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #006699; font-weight: bold; padding: 0px; margin: 0px;">empty</span>( $user ) || empty<span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #006699; font-weight: bold; padding: 0px; margin: 0px;">empty</span>( $password ) )</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">{</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #006699; font-weight: bold; padding: 0px; margin: 0px;">return</span> 0;</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">}</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">$ch = curl_init( );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt( $ch, CURLOPT_REFERER, <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“http://mail.sina.com.cn/index.html”</span> );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt( $ch, CURLOPT_HEADER, true );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt( $ch, CURLOPT_USERAGENT, USERAGENT );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt( $ch, CURLOPT_COOKIEJAR, COOKIEJAR );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt( $ch, CURLOPT_TIMEOUT, TIMEOUT );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt( $ch, CURLOPT_URL, <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“http://mail.sina.com.cn/cgi-bin/login.cgi”</span> );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt( $ch, CURLOPT_POST, true );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_setopt( $ch, CURLOPT_POSTFIELDS, <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“&amp;logintype=uid&amp;u=”</span>.urlencode( $user ).<span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“&amp;psw=”</span>.$password );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">$contents = curl_exec( $ch );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">curl_close( $ch );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #006699; font-weight: bold; padding: 0px; margin: 0px;">if</span> ( !preg_match( <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“/Location: (.*)\/cgi\/index\.php\?check_time=(.*)n/”</span>, $contents, $matches ) )</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">{</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #006699; font-weight: bold; padding: 0px; margin: 0px;">return</span> 0;</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">}<span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #006699; font-weight: bold; padding: 0px; margin: 0px;">else</span>{</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #006699; font-weight: bold; padding: 0px; margin: 0px;">return</span> 1;</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">}</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">}</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">define( <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“USERAGENT”</span>, $_SERVER[<span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">'HTTP_USER_AGENT'</span>] );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">define( <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“COOKIEJAR”</span>, tempnam( <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“/tmp”</span>, <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“cookie”</span> ) );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">define( <span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“TIMEOUT”</span>, 500 );</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">echo checklogin(<span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“zhangying215&#8243;</span>,<span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: blue; padding: 0px; margin: 0px;">“xtaj227&#8243;</span>);</span></li>
<li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 3px; border-style: initial; border-color: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f8f8f8; border-left-style: solid; border-left-color: #6ce26c; line-height: 14px; margin: 0px;"><span style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; padding: 0px; margin: 0px;">?&gt;</span></li>
</ol>
</div>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;"><strong>打开/tmp下面的cookie文件看一下</strong></p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;"># Netscape HTTP Cookie File<br />
# http://curl.haxx.se/rfc/cookie_spec.html<br />
# This file was generated by libcurl! Edit at your own risk.</p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px;">mail.sina.com.cn    FALSE    /    FALSE    0    SINAMAIL-WEBFACE-SESSID    65223c4bd8900284ed463d2a3e1ac182<br />
#HttpOnly_.sina.com.cn    TRUE    /    FALSE    0    SUE    es%3D8d96db0820c6c79922ad57d422f575e8%26ev%3Dv0%26es2%3Dcddfb8400dc5ca95902367ddcd7f57dd<br />
.sina.com.cn    TRUE    /    FALSE    0    SUP    cv%3D1%26bt%3D1286900433%26et%3D1286986833%26lt%3D1%26uid%3D1445632344%26user%3D%25E5%25BC%25A0%25E6%2598%25A02001%26ag%3D2%26name%3Dzhangying20015%2540sina.com%26nick%3D%25E5%25BC%25A0%25E6%2598%25A02001%26sex%3D1%26ps%3D0%26email%3Dzhangying20015%2540sina.com%26dob%3D1982-07-18<br />
#HttpOnly_.sina.com.cn    TRUE    /    FALSE    0    SID    BihcallomxMx-QZxzGrOlcSQx%2F0B%2F0cmr.NyQ%2F0B%2FcmGGalmarlmcHrcGlSmrmxmfxal_CBZ%2F_afugCmmGirBYHm0Bc%40fr5ciZiGG5i<br />
#HttpOnly_.sina.com.cn    TRUE    /    FALSE    0    SPRIAL    bfb4102951fd5892a3fd5b42d442cd26<br />
#HttpOnly_.sina.com.cn    TRUE    /    FALSE    0    SINA_USER    %D5%C5%D2001</p>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/06/17/715/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Mongodb 非关系数据（MongoDB）</title>
		<link>http://www.wangchao123.com/2011/05/12/712</link>
		<comments>http://www.wangchao123.com/2011/05/12/712#comments</comments>
		<pubDate>Thu, 12 May 2011 08:11:00 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=712</guid>
		<description><![CDATA[MongoDB MongoDB是一个介于关系数据库和非关系数据库之间的产品，是非关系数据库当中功能最丰富，最像关系数据库的。他支持的数据结构非常松散，是类似json的bjson格式，因此可以存储比较复杂的数据类型。Mongo最大的特点是他支持的查询语言非常强大，其语法有点类似于面向对象的查询语言，几乎可以实现类似关系数据库单表查询的绝大部分功能，而且还支持对数据建立索引。它的特点是高性能、易部署、易使用，存储数据非常方便。 主要功能特性： ◆ 面向集合存储，易存储对象类型的数据　　“面向集合”（Collenction-Orented），意思是数据被分组存储在数据集中，被称为一个集合（Collenction)。每个 集合在数据库中都有一个唯一的标识名，并且可以包含无限数目的文档。集合的概念类似关系型数据库（RDBMS）里的表（table），不同的是它不需要定 义任何模式（schema)。 ◆ 模式自由　　模式自由（schema-free)，意味着对于存储在mongodb数据库中的文件，我们不需要知道它的任何结构定义。如果需要的话，你完全可以把不同结构的文件存储在同一个数据库里。 ◆支持动态查询 ◆支持完全索引，包含内部对象 ◆支持查询 ◆支持复制和故障恢复 ◆使用高效的二进制数据存储，包括大型对象（如视频等） ◆自动处理碎片，以支持云计算层次的扩展性 ◆支持RUBY，PYTHON，JAVA，C++，PHP等多种语言 ◆文件存储格式为BSON（一种JSON的扩展）　　BSON（Binary Serialized dOcument Format）存储形式是指：存储在集合中的文档，被存储为键-值对的形式。键用于唯一标识一个文档，为字符串类型，而值则可以是各中复杂的文件类型。 ◆可通过网络访问　　MongoDB服务端可运行在Linux、Windows或OS X平台，支持32位和64位应用，默认端口为27017。推荐运行在64位平台，因为MongoDB在32位模式运行时支持的最大文件尺寸为2GB。　　MongoDB把数据存储在文件中（默认路径为：/data/db），为提高效率使用内存映射文件进行管理。]]></description>
			<content:encoded><![CDATA[<div id="page" style="margin-left: auto; margin-right: auto; background-image: url(http://img.baidu.com/img/baike/s/nav-bg.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #fafafa; background-position: 0px -34px; background-repeat: repeat no-repeat;">
<div id="content-wrap" style="width: 1000px; zoom: 1;">
<div id="content" style="width: 1000px; min-height: 1px; font-size: 14px; word-wrap: break-word; word-break: break-all; margin-left: auto; margin-right: auto; margin-top: 14px;">
<div style="zoom: 1; margin-right: 255px; background-image: url(http://img.baidu.com/img/baike/s/c-bg.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; padding-bottom: 3px; background-position: initial initial; background-repeat: initial initial;">
<div style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; margin-top: 0px; margin-right: 3px; margin-bottom: 0px; margin-left: 0px; padding-top: 16px; padding-right: 30px; padding-bottom: 10px; padding-left: 20px; border-top-width: initial; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: none; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: #dddddd; border-bottom-color: #dddddd; border-left-color: #dddddd; clear: both; zoom: 1; background-position: initial initial; background-repeat: initial initial;">
<div style="line-height: 24px;">
<div id="lemmaContent-0" style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">
<h3 style="margin-top: 15px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; font-size: 16px; font-family: Arial; line-height: 22px; clear: both; padding: 0px;"><span>MongoDB</span></h3>
</div>
<div id="lemmaContent-0" style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">MongoDB是一个介于关系数据库和非关系数据库之间的产品，是非关系数据库当中功能最丰富，最像关系数据库的。他支持的数据结构非常松散，是类似json的bjson格式，因此可以存储比较复杂的数据类型。Mongo最大的特点是他支持的查询语言非常强大，其语法有点类似于面向对象的查询语言，几乎可以实现类似关系数据库单表查询的绝大部分功能，而且还支持对数据建立索引。它的特点是高性能、易部署、易使用，存储数据非常方便。</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;"><strong>主要功能特性</strong>：</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆ 面向集合存储，易存储对象类型的数据　　“面向集合”（Collenction-Orented），意思是数据被分组存储在数据集中，被称为一个集合（Collenction)。每个 集合在数据库中都有一个唯一的标识名，并且可以包含无限数目的文档。集合的概念类似关系型数据库（RDBMS）里的表（table），不同的是它不需要定 义任何模式（schema)。</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆ 模式自由　　模式自由（schema-free)，意味着对于存储在mongodb数据库中的文件，我们不需要知道它的任何结构定义。如果需要的话，你完全可以把不同结构的文件存储在同一个数据库里。</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆支持动态查询</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆支持完全索引，包含内部对象</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆支持查询</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆支持复制和故障恢复</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆使用高效的二进制数据存储，包括大型对象（如视频等）</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆自动处理碎片，以支持云计算层次的扩展性</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆支持RUBY，PYTHON，JAVA，C++，PHP等多种语言</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆文件存储格式为BSON（一种JSON的扩展）　　BSON（Binary Serialized dOcument Format）存储形式是指：存储在集合中的文档，被存储为键-值对的形式。键用于唯一标识一个文档，为字符串类型，而值则可以是各中复杂的文件类型。</div>
<div style="letter-spacing: 0.5px; width: 690px; overflow-x: hidden; overflow-y: hidden;">◆可通过网络访问　　MongoDB服务端可运行在Linux、Windows或OS X平台，支持32位和64位应用，默认端口为27017。推荐运行在64位平台，因为MongoDB在32位模式运行时支持的最大文件尺寸为2GB。　　MongoDB把数据存储在文件中（默认路径为：/data/db），为提高效率使用内存映射文件进行管理。</div>
</div>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/05/12/712/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>基于Xcode4开发第一个iPhone程序：“Hello World” (转 自 宝玉博客)</title>
		<link>http://www.wangchao123.com/2011/05/12/686</link>
		<comments>http://www.wangchao123.com/2011/05/12/686#comments</comments>
		<pubDate>Thu, 12 May 2011 05:43:40 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[iphone Mac 手机应用开发]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[手机]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=686</guid>
		<description><![CDATA[转自: http://www.cnblogs.com/dotey/archive/2011/05/12/2043939.html 基于Xcode4开发第一个iPhone程序：“Hello World” 项目要求 写一个iPhone程序，在屏幕正中显示文字“Hello Word”，粗体，字体大小26磅，字体颜色红色，有黑色阴影，阴影光源为左上角，偏移1像素，支持设备旋转。 需求分析 在开始之前，我们首先来分析一下项目需求，这是一个非常简单的项目，只要在屏幕上显示一段“Hello World”的文字，当然还有一些附加条件： 对字体、字体颜色、字体大小有要求，有阴影效果 要求文字显示在屏幕正中 支持设备旋转，并且无论设备如何旋转，文字都还是显示在屏幕正中 根据这些需求，我们将从简单到复杂，逐步来实现，分成2步来实现： 在屏幕上显示文字，设置字体和字体大小，让文字显示在屏幕正中心 支持设备旋转，并且保证旋转后文字还是居中状态 产品设计 iPhone4之前的屏幕是320&#215;480，到iPhone4的时候，支持了高清屏，屏幕分辨率变成了640&#215;960。iPhone支持四个方向的旋转的，横屏和竖屏表现略有差异，因为项目需求要求支持屏幕旋转，所以针对横屏和竖屏，界面表现有所差异，简单画一下原型设计图如下： 系统分析和设计 如果我们还没iOS下的开发经验，那么首先需要去查阅一些相关资料，让我们知道如何来开发一个iphone程序。苹果为iOS的开发者提供了一个非常详细和全面的网站：“iOS Developer Center”，网址：http://developer.apple.com/ios。在iOS Dev Center，有所有iOS SDK的类文档、入门文档、各种开发指南、示例代码库等，开发iOS平台的项目，免不了要经常上来查阅一些相关资料。不过比较遗憾的是，目前iOS Dev Center的文档和资料还是英文为主，中文资料较少，对于英文阅读不好的同学是一个考验。 现在，我们从技术角度来分析一下如何实现项目需求。同样一个项目，无疑是有很多种技术方案来实现的，所以我们有必要定一个原则，来帮助我们选择合适的方案，这个原则就是简单实用原则：“我们尽可能采用简单并且实用的技术方案，避免使用复杂的技术方案，把时间和精力浪费在一些华而不实的技巧上面”，本着这个原则，我们来开始对项目需求进行技术方案的选择： 在屏幕上显示特定字体和大小的文字 要在屏幕上显示特定字体和大小的文字，我们需要先看看iOS SDK中是否已经提供了简单实用的方式来显示文字，在iOS Dev Center中，有一篇文章“iOS Human Interface Guidelines”，专门讲解了iOS中用户界面相关的知识，从中我们可以系统的了解iOS的界面构成，各种基本界面元素，并且根据其中的说明，可以找到UILabel控件是最适合我们项目需求的控件，当然也有复杂的技术方案，就是采用在界面上自画的方式，根据简单实用原则，我们就使用UILabel这种iOS自带控件就可以了。 在开始使用UILabel之前，我们需要先来学习了解一下UILabel控件，想要了解UILabel控件的功能，在iOS Dev Center中，找到“UILabel Class Reference”，从中我们可以看到UILabel的介绍和所有属性、方法等详细的说明文档。 文档相当全面，不过对于我们来说，关键还是要去获取项目相关的资料，从文档中，我们可以逐一找到我们显示文字需要的相关属性： text: Label显示的文字，类型为NSString类，也就是本项目需求中要显示的“Hello World”。 textAlignment: 文字在Label内的对其方式，类型为UITextAlignment枚举，在本项目需求中，要求文字在屏幕正中显示，对应的属性值为UITextAlignmentCenter。 font: 文字的字体和大小，类型为UIFont类，也就是本项目需求中要求的：“字体为粗体，字体大小26磅”，对应代码为：[UIFontboldSystemFontOfSize:26]。 textColor: 文字的颜色，类型为UIColor类，也就是本项目需求中要求的：“字体颜色红色”，对应代码为：[UIColor redColor]。 shadowColor: Label文字的阴影颜色，类型为UIColor类，也就是本项目需求中要求的：“有黑色阴影”，对应代码为：[UIColorblackColor]。 shadowOffset: [...]]]></description>
			<content:encoded><![CDATA[<div style="padding-left: 70px; padding-right: 40px; font-size: 10pt; line-height: 19px;">
<h2 style="margin-top: 10px; font-size: 1em;"></h2>
<h2 style="margin-top: 10px; font-size: 1em;">转自: <a href="http://www.cnblogs.com/dotey/archive/2011/05/12/2043939.html">http://www.cnblogs.com/dotey/archive/2011/05/12/2043939.html</a></h2>
<h2 style="margin-top: 10px; font-size: 1em;"><a id="ctl02_TitleUrl" style="color: #0066aa; text-decoration: none;" href="http://www.cnblogs.com/dotey/archive/2011/05/12/2043939.html">基于Xcode4开发第一个iPhone程序：“Hello World”</a></h2>
<div style="font-size: 10pt; line-height: 19px;">
<div id="cnblogs_post_body">
<h2 style="margin-top: 10px; font-size: 1em;">项目要求</h2>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">写一个iPhone程序，在屏幕正中显示文字“Hello Word”，粗体，字体大小26磅，字体颜色红色，有黑色阴影，阴影光源为左上角，偏移1像素，支持设备旋转。</p>
<h2 style="margin-top: 10px; font-size: 1em;">需求分析</h2>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">在开始之前，我们首先来分析一下项目需求，这是一个非常简单的项目，只要在屏幕上显示一段“Hello World”的文字，当然还有一些附加条件：</p>
<ul>
<li>对字体、字体颜色、字体大小有要求，有阴影效果</li>
<li>要求文字显示在屏幕正中</li>
<li>支持设备旋转，并且无论设备如何旋转，文字都还是显示在屏幕正中</li>
</ul>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">根据这些需求，我们将从简单到复杂，逐步来实现，分成2步来实现：</p>
<ol style="margin-left: 2em;">
<li style="list-style-type: decimal;">在屏幕上显示文字，设置字体和字体大小，让文字显示在屏幕正中心</li>
<li style="list-style-type: decimal;">支持设备旋转，并且保证旋转后文字还是居中状态</li>
</ol>
<h2 style="margin-top: 10px; font-size: 1em;">产品设计</h2>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">iPhone4之前的屏幕是320&#215;480，到iPhone4的时候，支持了高清屏，屏幕分辨率变成了640&#215;960。iPhone支持四个方向的旋转的，横屏和竖屏表现略有差异，因为项目需求要求支持屏幕旋转，所以针对横屏和竖屏，界面表现有所差异，简单画一下原型设计图如下：</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">
<a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242026761.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134341k4b.jpg" alt="201105120238.jpg" width="246" height="478" /></a> <a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120241563485.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134341olJ.jpg" alt="201105120238.jpg" width="480" height="246" /></a></p>
<h2 style="margin-top: 10px; font-size: 1em;">系统分析和设计</h2>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">如果我们还没iOS下的开发经验，那么首先需要去查阅一些相关资料，让我们知道如何来开发一个iphone程序。苹果为iOS的开发者提供了一个非常详细和全面的网站：“iOS Developer Center”，网址：<a style="color: #0066aa; text-decoration: none;" href="http://developer.apple.com/devcenter/ios/index.action">http://developer.apple.com/ios</a>。在iOS Dev Center，有所有iOS SDK的类文档、入门文档、各种开发指南、示例代码库等，开发iOS平台的项目，免不了要经常上来查阅一些相关资料。不过比较遗憾的是，目前iOS Dev Center的文档和资料还是英文为主，中文资料较少，对于英文阅读不好的同学是一个考验。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242121310.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/13434303h.jpg" alt="201105111713.jpg" width="640" height="506" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">现在，我们从技术角度来分析一下如何实现项目需求。同样一个项目，无疑是有很多种技术方案来实现的，所以我们有必要定一个原则，来帮助我们选择合适的方案，这个原则就是简单实用原则：“我们尽可能采用简单并且实用的技术方案，避免使用复杂的技术方案，把时间和精力浪费在一些华而不实的技巧上面”，本着这个原则，我们来开始对项目需求进行技术方案的选择：</p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">在屏幕上显示特定字体和大小的文字</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">要在屏幕上显示特定字体和大小的文字，我们需要先看看iOS SDK中是否已经提供了简单实用的方式来显示文字，在iOS Dev Center中，有一篇文章“<a style="color: #0066aa; text-decoration: none;" href="http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html%23//apple_ref/doc/uid/TP40006556-CH1-SW1">iOS Human Interface Guidelines</a>”，专门讲解了iOS中用户界面相关的知识，从中我们可以系统的了解iOS的界面构成，各种基本界面元素，并且根据其中的说明，可以找到UILabel控件是最适合我们项目需求的控件，当然也有复杂的技术方案，就是采用在界面上自画的方式，根据简单实用原则，我们就使用UILabel这种iOS自带控件就可以了。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242049627.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134344MMJ.jpg" alt="201105112127.jpg" width="640" height="461" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">在开始使用UILabel之前，我们需要先来学习了解一下UILabel控件，想要了解UILabel控件的功能，在iOS Dev Center中，找到“<a style="color: #0066aa; text-decoration: none;" href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UILabel_Class/Reference/UILabel.html%23//apple_ref/doc/uid/TP40006797">UILabel Class Reference</a>”，从中我们可以看到UILabel的介绍和所有属性、方法等详细的说明文档。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242061871.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134344bqp.jpg" alt="201105112035.jpg" width="640" height="461" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">文档相当全面，不过对于我们来说，关键还是要去获取项目相关的资料，从文档中，我们可以逐一找到我们显示文字需要的相关属性：</p>
<ul>
<li><strong>text</strong>: Label显示的文字，类型为NSString类，也就是本项目需求中要显示的“Hello World”。</li>
<li><strong>textAlignment</strong>: 文字在Label内的对其方式，类型为UITextAlignment枚举，在本项目需求中，要求文字在屏幕正中显示，对应的属性值为UITextAlignmentCenter。</li>
<li><strong>font</strong>: 文字的字体和大小，类型为UIFont类，也就是本项目需求中要求的：“字体为粗体，字体大小26磅”，对应代码为：<span style="line-height: 21px; font-family: Menlo; font-size: 14px; color: #3e2280;"><span style="line-height: 21px; color: #000000;">[</span><span style="line-height: 21px; color: #7041a7;">UIFont</span>boldSystemFontOfSize<span style="line-height: 21px; color: #000000;">:</span><span style="line-height: 21px; color: #2f33d5;">26</span><span style="line-height: 21px; color: #000000;">]</span></span>。</li>
<li><strong>textColor</strong>: 文字的颜色，类型为UIColor类，也就是本项目需求中要求的：“字体颜色红色”，对应代码为：<span style="line-height: 21px; font-family: Menlo; font-size: 14px; color: #3e2280;"><span style="line-height: 21px; color: #000000;">[</span><span style="line-height: 21px; color: #7041a7;">UIColor</span> redColor<span style="line-height: 21px; color: #000000;">]</span></span>。</li>
<li><strong>shadowColor</strong>: Label文字的阴影颜色，类型为UIColor类，也就是本项目需求中要求的：“有黑色阴影”，对应代码为：<span style="line-height: 21px; font-family: Menlo; font-size: 14px; color: #3e2280;"><span style="line-height: 21px; color: #000000;">[</span><span style="line-height: 21px; color: #7041a7;">UIColor</span>blackColor<span style="line-height: 21px; color: #000000;">]</span></span>。</li>
<li><strong>shadowOffset</strong>: Label文字阴影的偏移方向和偏移量，类型为CGSize，也就是本项目需求中要求的：“阴影光源为左上角，偏移1像素”，对应代码为：<span style="line-height: 21px; font-family: Menlo; font-size: 14px;">[CGSizeMake(<span style="line-height: 21px; color: #2f33d5;">1</span>, <span style="line-height: 21px; color: #2f33d5;">1</span>)]</span>。</li>
</ul>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">让文字显示在屏幕正中心</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">要让文字显示在屏幕正中心，我们要优先考虑设置UILabel相关属性达到目的的方式，如果没有UILabel相关属性支持，那么我们就必须根据UILabel占的大小和屏幕大小来计算它应该摆放的坐标，从而实现让文字显示在屏幕正中心。在UILabel的文档中，没有发现有属性设置它的坐标，也没有设置对其的属性，这是不是代表UILabel不支持呢？不要忽略一个问题，iOS所用的编程语言是Objective-C，这个一个类似于C语言的很好的支持面向对象特性的语言，面向对象有个很重要的特性叫继承，同样对于UILabel类来说，它是有父类的，也就是UILabel父类支持的属性，UILabel都是支持的，在UILabel文档的首页，我们可以看到UILabel是从UIView继承的，所以我们可以链接到“<a style="color: #0066aa; text-decoration: none;" href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html%23//apple_ref/doc/uid/TP40006816">UIView Class Reference</a>”文档。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242045658.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134344vh8.jpg" alt="201105112034.jpg" width="640" height="461" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">从文档中，我们可以找到2个重要属性，用来实现文字显示在屏幕正中：</p>
<ul>
<li><strong>frame</strong>: Label的位置和尺寸属性，类型为CGRect，在本项目需求中，要求显示在屏幕正中，就需要通过Label控件的frame属性的size值，结合主界面的尺寸，计算出x，y坐标值，以保证Label显示在屏幕正中。</li>
<li><strong>autoresizingMask</strong>: 这个属性表示控件在其父容器尺寸发生变化时，它是怎么自动调整其尺寸或上下左右各个方向边距的。</li>
</ul>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><span style="line-height: 21px; font-size: 14px; font-weight: bold;">支持屏幕旋转</span></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">iPhone程序默认不支持屏幕旋转，那么如何让界面支持旋转呢？在iOS Dev Center中，可以找到“<a style="color: #0066aa; text-decoration: none;" href="http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html#//apple_ref/doc/uid/TP40007457-CH101-SW24">View Controller Programming Guide for iOS</a>”，在其中的“Custom View Controllers”一章中专门有一节“Managing a View Controller&#8217;s Interface Orientation”，说明了如何让你的iOS界面支持设备旋转：</p>
<ul>
<li>重写对应的View Controller的“shouldAutorotateToInterfaceOrientation:”方法，在方法中申明支持的方向。</li>
<li>配置对应的View Controller中的View的autoresizingMask属性，以适应因为界面旋转导致的布局变化。在本项目中，项目需求中要求设备在旋转也保证文字居中，利用这个属性，可以实现在界面旋转后，窗体宽度和高度发生变化时，UILabel还能继续居中。</li>
</ul>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120241577846.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/13434615j.jpg" alt="201105112158.jpg" width="640" height="461" /></a></p>
<h2 style="margin-top: 10px; font-size: 1em;">项目开发</h2>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">熟悉Xcode 4</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">经过前期的准备工作后，现在可以开始基于Xcode4进行实际的项目开发。对于Xcode4，在iOS Dev Center中，找到“<a style="color: #0066aa; text-decoration: none;" href="http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/Introduction/Introduction.html">Xcode 4 User Guide</a>”，这是一个专门针对Xcode 4的说明和使用指南，非常详细。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120241508016.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134347I67.jpg" alt="201105112350.jpg" width="640" height="461" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">在Xcode 4中，整合了原来专门用来编辑Mac或iOS项目界面的Interface Builder软件，“<a style="color: #0066aa; text-decoration: none;" href="http://developer.apple.com/library/ios/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/Introduction/Introduction.html">Xcode 4 User Guide</a>”中专门有一章“Designing User Interfaces in Xcode”来讲述如何在Xcode 4中编辑界面。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242078425.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134347e96.jpg" alt="201105120043.jpg" width="640" height="461" /></a></p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">创建新项目</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">启动Xcode4后，首先会有一个欢迎窗口，通过它，点击“Create a new Xcode project”，可以直接开始创建项目</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120241535210.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134347XoI.jpg" alt="201105112227.jpg" width="640" height="415" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">当然也可以通过菜单或者快捷方式来开始创建新项目</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242084215.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134348wia.jpg" alt="201105112231.jpg" width="640" height="203" /></a></p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">选择新项目模板</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">为方便生成项目，Xcode4默认提供了几种项目模板：</p>
<ul>
<li><strong>Navigation-based Application</strong>: 该模板适用与需要界面导航的应用，基于该模板生成的应用程序，带一个导航，显示一个列表项</li>
<li><strong>OpenGL ES Application</strong>: 该模板适用于基于OpenGL ES的应用程序，例如游戏类程序。基于该模板生成的应用程序，带一个用来输出OpenGL ES场景的视图和一个支持动画的视图</li>
<li><strong>Splite View-based Application</strong>: 该模板适用于需要用到左右分栏视图的iPad程序，基于该模板生成的应用程序，提供了一个左右分栏的界面控件</li>
<li><strong>Tab Bar Application</strong>: 该模板适用于适用采用标签页的应用程序，基于该模板生成的应用程序，默认带有标签页</li>
<li><strong>Utility Application</strong>: 该模板适用与有一个主界面和一个信息页的应用，基于该模板生成的应用程序，主界面上有一个信息按钮，点击后，有一个翻转动画，切换到另一个信息界面</li>
<li><strong>View-based Application</strong>: 该模板适用于单一界面的应用，基于该模板生成的应用程序，只有一个空白界面视图</li>
<li><strong>Window-based Application</strong>: 该模板适用于空白的应用程序，基于该模板生成的应用程序，只有一个窗体，没有任何视图，需要手动添加</li>
</ul>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120241536813.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/1343485rz.jpg" alt="201105112234.jpg" width="640" height="431" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">对于我们的Hello World项目来说，最适合的项目模板是“View-based Application”，我们只要基于它创建一个单一带有空白视图的应用，然后再将UILabel拖到上面就可以实现基本功能。</p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">项目基本选项</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">点击下一步，进入“Choose options for your new project”界面，在这里，可以选择设置项目的基本选项，其中：</p>
<ul>
<li><strong>Product Name</strong>: 指产品名称，在这里项目中，我们直接命名为“Hello World”</li>
<li><strong>Company Identifier</strong>: 公司标识符，一般命名规则为 “com.公司名”</li>
<li><strong>Bundle Identifier</strong>: 指包标识符，用于唯一标识应用程序，默认会根据公司标识符和产品名来组合生成</li>
<li><strong>Device Family</strong>: 指该应用支持的设备类型，共三个选项：iPhone、iPad、Universal（即iPhone、iPad通用）</li>
<li><strong>Include Unite Tests</strong>: 是否包含单元测试代码模板，如果勾选，Xcode会帮助生成单元测试代码模板</li>
</ul>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120241493197.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134348jVh.jpg" alt="201105112323.jpg" width="640" height="418" /></a></p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">选择存储路径</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">点击Next按钮后，进入选择文件存储路径界面，在这里，可以选择要存储项目的目录。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242083310.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134349oeL.jpg" alt="201105112332.jpg" width="640" height="478" /></a></p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">项目创建完成</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">点击“Create”按钮，项目创建完成，弹出项目窗口。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120241552537.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134349NXP.jpg" alt="201105112337.jpg" width="640" height="412" /></a></p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">试运行项目</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">经过上面的步骤，我们已经基于模板创建了一个项目，在开始开发前，我们可以尝试先试运行一下项目，看看效果。点击Xcode左上角的“Run”按钮，Xcode即开始对项目进行编译，编译完成后，会弹出iPhone模拟器，在模拟器中运行项目，当然我们的项目现在运行起来还只能看到一个空白的界面。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120241493164.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134349BW6.jpg" alt="201105120009.jpg" width="368" height="716" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">点Xcode左上角的“Stop”按钮，停止运行项目。</p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">编辑界面文件</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">一般创建一个新项目，在项目中会包含一个或多个界面文件，这些界面文件一般称之为“nib文件”，扩展名为nib或xib。或者通过向导创建一个新的View Controller的时候，Xcode会包含一个对应的nib文件，一个头文件和一个实现文件。在我们刚刚以View-based Application为模板创建的Hello World项目中，“Hello_WorldViewController.xib”就是主界面的nib文件。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">在Xcode左侧选中“Hello_WorldViewController.xib”文件，并点击工具栏的“Hide or show the Navigator”和“Hide or show the Utilities ”按钮，隐藏左侧Navigator区域，显示Utility区域，这样我们就可以开始在Xcode 4中来编辑界面。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120241543716.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134349qCg.jpg" alt="201105120048.jpg" width="640" height="412" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><span style="line-height: 21px; font-size: 14px; font-weight: bold;">添加Label到界面中</span></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">从对象库中，找到我们所需要的Label控件对象，拖动到主界面中，即完成Label控件的添加</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120241516521.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134350Y7w.jpg" alt="201105120102.jpg" width="640" height="412" /></a></p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">设置Label控件属性</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">选中新添加的Label控件，点击Inspector selector bar区域的“Show the Attributes inspector”按钮，切换到属性编辑界面，分别设置以下属性：</p>
<ul>
<li><strong>Text</strong>: 输入“Hello World”</li>
<li><strong>Alignment</strong>: 选择居中对齐</li>
<li><strong>Font</strong>: 选择“Helvetical Bold 26.0”</li>
<li><strong>Text Color</strong>: 选择红色</li>
<li><strong>Shadow</strong>: 选择黑色（Black Color）</li>
<li><strong>Shadow Offset</strong>: Horizontal和Vertical的值分别输入1</li>
</ul>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242103144.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134350HJZ.jpg" alt="201105120125.jpg" width="640" height="412" /></a></p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">设置Label控件的大小和位置</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">在上面的步骤中设置好Label的相关属性后，发现文字特别小，而且显示不完整，并非我们所选择的字体大小，这是由于UILabel有一个属性“adjustsFontSizeToFitWidth”，默认值是“YES”，如果这个属性的值为YES，并且Label的numberOfLines属性值是1，它会根据Label的宽度来自动调整字体大小，通过Xcode新添加的Label，默认宽度比较小，按照正常的26磅大小的字体，无法完整显示，所以就字体大小就被自动调整了，导致显示的和我们期望的不一样。解决这个问题很简单，就是我们重新设置一下Label的宽度，以让其可以完整显示文字。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">选中新添加的Label控件，点击Inspector selector bar区域的“Show the Size inspector”按钮，切换到尺寸和位置设置界面，对宽度进行调整，这里我们给Label设置一个足够的宽度和高度：200&#215;40，以保证字体不会被缩小。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">接下来，就是要调整Label的位置，让它显示在屏幕的正中间。在Xcode中，用鼠标拖动Label，拖动过程中Xcode有辅助线来帮助定位，很容易就可以找到正中心的位置。当然也可以通过简单的计算得到Label如果要显示在正中心，坐标应该为：x = (屏幕宽度 &#8211; Label宽度) / 2 = (320 &#8211; 200) / 2 = 60; y = (屏幕高度 &#8211; 状态栏高度 &#8211; Label高度) / 2 = (480 &#8211; 20 &#8211; 40) / 2 = 210;</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242027874.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134350Vly.jpg" alt="201105120142.jpg" width="640" height="412" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">对修改过的xib文件保存，运行项目，看看效果</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/201105120242028920.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/1343502IN.jpg" alt="201105120151.jpg" width="368" height="716" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">就这样，我们已经完成了第一步：在屏幕上显示文字，设置字体和字体大小，让文字显示在屏幕正中心。下一步，我们要让它支持旋转，并且旋转后，文字还是显示在屏幕正中。</p>
<h3 style="font-size: 10pt; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #d6d6d6; color: #000000; background-color: transparent;">支持设备旋转</h3>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">前面我们已经学习了解过，要支持设备宣传，要做如下工作：</p>
<ul>
<li>重写对应的View Controller的“shouldAutorotateToInterfaceOrientation:”方法，在方法中申明支持的方向。也就是首先要重写“Hello_WorldViewController.m”中的“shouldAutorotateToInterfaceOrientation:”方法</li>
<li>配置对应的View Controller中的View的autoresizingMask属性，以适应因为界面旋转导致的布局变化。也就是要设置好Label控件的autoresizingMask属性。</li>
</ul>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">还是在界面文件中，选中Label，在尺寸和位置设置界面，通过点击Autosizing中的红色线条，设置Label对上下左右四个方向以及宽度和高度都自动调整，这样就可以保证在设备旋转后，界面的宽度和高度发生改变后，控件对上下左右四个方向的位置以及长度和宽度也会随着一起调整，由于已经设置了文字在Label内部是居中对齐的，就可以保证文字显示在界面居中的位置。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134351yjI.jpg" alt="201105120210.jpg" width="259" height="270" /></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">点击工具栏的“Hide or show the Navigator”和“Hide or show the Utilities ”按钮，显示左侧Navigator区域，隐藏Utility区域，在左侧Navigator区域，选中“Hello_WorldViewController.m”文件，找到“shouldAutorotateToInterfaceOrientation:”方法，对其进行重写，重写后代码如下</p>
<div style="font: normal normal normal 14px/normal Menlo;">- (<span style="line-height: 21px; color: #b831a1;">BOOL</span>)shouldAutorotateToInterfaceOrientation:(<span style="line-height: 21px; color: #7041a7;">UIInterfaceOrientation</span>)interfaceOrientation</div>
<div style="font: normal normal normal 14px/normal Menlo;">{</div>
<div style="font: normal normal normal 14px/normal Menlo; color: #058310; text-indent: 4em;">// Return YES for supported orientations</div>
<div style="font: normal normal normal 14px/normal Menlo; color: #b831a1; text-indent: 4em;">return YES<span style="line-height: 21px; color: #000000;">;</span></div>
<div style="font: normal normal normal 14px/normal Menlo;">}</div>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">对所做的修改进行保存，然后运行项目，弹出模拟器，通过调用模拟器的设备旋转菜单，让iPhone模拟器变成横屏，你将看到文字会自动调整位置，还是显示在屏幕正中的位置。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;"><a style="color: #0066aa; text-decoration: none;" href="http://images.cnblogs.com/cnblogs_com/dotey/201105/20110512024156420.jpg"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/05/134351hKV.jpg" alt="201105120213.jpg" width="640" height="328" /></a></p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">至此，我们就实现了项目的全部需求。</p>
<h2 style="margin-top: 10px; font-size: 1em;">项目总结</h2>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">通过Hello World这个简单项目，我们学习了如何基于Xcode 4分析和开发iOS项目，学习了如何通过iOS Dev Center获取需要的资料。</p>
<p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; text-indent: 0px;">源码下载：<a style="color: #0066aa; text-decoration: none;" href="https://github.com/JimLiu/The-practice-of-iPhone-application-development/tree/master/Hello%20World">https://github.com/JimLiu/The-practice-of-iPhone-application-development/tree/master/Hello%20World</a></p>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/05/12/686/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>9个很有发展潜力的PHP开源项目 (包括 iphone push 和 phpForAndroid) （转）</title>
		<link>http://www.wangchao123.com/2011/03/21/677</link>
		<comments>http://www.wangchao123.com/2011/03/21/677#comments</comments>
		<pubDate>Mon, 21 Mar 2011 10:41:02 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=677</guid>
		<description><![CDATA[介绍9个很有发展潜力的PHP开源项目 原文: http://developer.51cto.com/art/201101/243552.htm 2011年01月20日02:00 it168网站原创 作者：jacky / 译 编辑：董建伟 评论：0条 本文Tag： PHP开源项目 开源项目 PHP 开源 　　【IT168 专稿】PHP的开源世界可谓相当精彩，其中大家也接触的不少著名的PHP开源项目，比如Drupal、Sugar CMS、Joomla等等，但在本文中，笔者将选取9个最新知名度不是太高，但可在某些方面很实用，目前还在发展阶段，很有潜力的PHP开源项目。相信各位读者看了之后会惊叹：原来PHP还能干这么多事情。 　　1、PHP FOR Android 　　现在，iphone和Android大行其道，拥有它们已经成为一种潮流。而Android的市场份额也变的越来越大。 　　而现在除了可以用JAVA来编写Android应用外，还多了一种选择，那就是可以使用PHP去编写相关的Android应用了，这都要归功于一个开源项目Php For Android(http://phpforandroid.net/)。它实际上是利用了另外一个开源项目Scripting Layer for Android(SL4A)( http://code.google.com/p/android-scripting/)提供的Android接口API去实现的，任何支持SL4A的脚本语言(比如Javascript,Ruby, Perl,PHP,和Python)都能够通过接口直接跟操作系统打交道，编写应用。 　　如果想了解这个项目，可以阅读如下的这篇文章《Build Your First PHP for Android Application》。 　　2、PL/PHP 　　某些数据库任务涉及很复杂的逻辑计算，而不是简单使用几句SQL语句就可以解决问题。为了降低其复杂性，许多数据库的解决方案中提供了存储过程，它在一个子程序中封装了要完成任务的逻辑，这些子任何的功能其实就象PHP中的函数一样。 　　存储过程可以用相应的SQL去编写的，如微软的存储过程使用T-SQL,Oracle则采用PL-SQL。比如PostgreSQL数据库能执行由C,C++,Java，Ruby,Perl,Python编写的存储过程，而有了PL/php 开源项目(https://public.commandprompt.com/projects/plphp/wiki)，现在你可以使用PHP去编写存储过程了。 　　当安装了PL/PHP项目后，你就可以在PostgreSQL下执行使用PHP编写的存储过程了，可以使用你熟悉的PHP语法，十分简单。 　　3、PHP-QT 　　PHP-QT项目(http://developer.berlios.de/projects/php-qt/)允许你使用PHP语言去编写实现QT的功能，也就是说，可以使用PHP-QT去编写一些功能强大的桌面应用。所谓QT是一个跨平台的C++图形用户界面应用程序框架。它提供给应用程序开发者建立艺术级的图形用户界面所需的所用功能。Qt是完全面向对象的，很容易扩展，并且允许真正地组件编程。 　　但有点遗憾的是，这几年这个项目的发展有点迟缓了，如果确实有兴趣的话，建议也去研究下PHP-GTK这个项目(http://gtk.php.net/) 　　4、Phuby 　　最近,Ruby核心团队成员Aaron Patterson完成了phuby,它可以在Rails应用下运行php应用程序。项目的地址在https://github.com/tenderlove/phuby，尽管项目主持人Aaron发布了几个视频去证明phuby能让php在Rails下运行，但实际上在Rails社区中，估计phuby也只是一个实验品而已。 　　5、另外一个phuby 　　Sean Huber也发布了另外一个同名的项目，居然也叫phuby，但这个跟上面介绍那个是完全没任何关系的。项目地址在https://github.com/huberry/phuby。这个项目为php增加了几个有趣的功能，而只需要在php中设置include_path指向phuby的库位置就可以了。虽然该项目还是处在比较初级的阶段，但其实它已经是综合了php和ruby的一些特点了。 　　6、Objective-PHP and Moka 　　Objective-PHP [...]]]></description>
			<content:encoded><![CDATA[<div>
<h1>介绍9个很有发展潜力的PHP开源项目</h1>
</div>
<div>原文: <a href="http://developer.51cto.com/art/201101/243552.htm">http://developer.51cto.com/art/201101/243552.htm</a></p>
<p>2011年01月20日02:00 <!--511--><!--True--><a href="http://www.it168.com/" target="_blank">it168网站</a>原创 作者：jacky / 译 编辑：<a href="http://archive.it168.com/user/%b6%ad%bd%a8%ce%b0/" target="_blank">董建伟</a> 评论：<span id="page_CommentCount">0</span>条</div>
<p><!-- Tag --></p>
<div>本文Tag： <a href="http://tech.it168.com/chanel-4-tagid-28578-page-1.shtml" target="_blank">PHP开源项目</a> <a href="http://tech.it168.com/chanel-4-tagid-28255-page-1.shtml" target="_blank">开源项目</a> <a href="http://tech.it168.com/chanel-4-tagid-25797-page-1.shtml" target="_blank">PHP</a> <a href="http://tech.it168.com/chanel-4-tagid-25918-page-1.shtml" target="_blank">开源</a></div>
<div><a href="http://developer.51cto.com/art/201101/243552.htm"></a></div>
<p><!--wordstart--></p>
<div id="detailWord">
<p>　　【IT168 专稿】PHP的开源世界可谓相当精彩，其中大家也接触的不少著名的PHP开源项目，比如Drupal、Sugar CMS、Joomla等等，但在本文中，笔者将选取9个最新知名度不是太高，但可在某些方面很实用，目前还在发展阶段，很有潜力的PHP开源项目。相信各位读者看了之后会惊叹：原来PHP还能干这么多事情。</p>
<p>　　<strong>1、PHP FOR Android</strong></p>
<p>　　现在，iphone和Android大行其道，拥有它们已经成为一种潮流。而Android的市场份额也变的越来越大。</p>
<p>　　而现在除了可以用JAVA来编写Android应用外，还多了一种选择，那就是可以使用PHP去编写相关的Android应用了，这都要归功于一个开源项目Php For Android(http://phpforandroid.net/)。它实际上是利用了另外一个开源项目Scripting Layer for Android(SL4A)( http://code.google.com/p/android-scripting/)提供的Android接口API去实现的，任何支持SL4A的脚本语言(比如Javascript,Ruby, Perl,PHP,和Python)都能够通过接口直接跟<a title="操作系统" href="http://product.it168.com/list/b/0501_1.shtml" target="_blank">操作系统</a>打交道，编写应用。</p>
<p>　　如果想了解这个项目，可以阅读如下的这篇文章《<a href="http://www.developer.com/lang/php/article.php/3904261/Build-Your-First-PHP-for-Android-Application.htm" target="_blank">Build Your First PHP for Android Application</a>》。</p>
<p><strong>　　2、PL/PHP</strong></p>
<p>　　某些数据库任务涉及很复杂的逻辑计算，而不是简单使用几句SQL语句就可以解决问题。为了降低其复杂性，许多数据库的解决方案中提供了存储过程，它在一个子程序中封装了要完成任务的逻辑，这些子任何的功能其实就象PHP中的函数一样。</p>
<p>　　存储过程可以用相应的SQL去编写的，如微软的存储过程使用T-SQL,Oracle则采用PL-SQL。比如PostgreSQL数据库能执行由C,C++,Java，Ruby,Perl,Python编写的存储过程，而有了PL/php 开源项目(https://public.commandprompt.com/projects/plphp/wiki)，现在你可以使用PHP去编写存储过程了。</p>
<p>　　当安装了PL/PHP项目后，你就可以在PostgreSQL下执行使用PHP编写的存储过程了，可以使用你熟悉的PHP语法，十分简单。</p>
<p><strong>　　3、PHP-QT</strong></p>
<p>　　PHP-QT项目(http://developer.berlios.de/projects/php-qt/)允许你使用PHP语言去编写实现QT的功能，也就是说，可以使用PHP-QT去编写一些功能强大的桌面应用。所谓QT是一个跨平台的C++图形用户界面应用程序框架。它提供给应用程序开发者建立艺术级的图形用户界面所需的所用功能。Qt是完全面向对象的，很容易扩展，并且允许真正地组件编程。</p>
<p>　　但有点遗憾的是，这几年这个项目的发展有点迟缓了，如果确实有兴趣的话，建议也去研究下PHP-GTK这个项目(http://gtk.php.net/)</p>
<p><strong>　　4、Phuby</strong></p>
<p>　　最近,Ruby核心团队成员Aaron Patterson完成了phuby,它可以在Rails应用下运行php应用程序。项目的地址在https://github.com/tenderlove/phuby，尽管项目主持人Aaron发布了几个视频去证明phuby能让php在Rails下运行，但实际上在Rails社区中，估计phuby也只是一个实验品而已。</p>
<p><strong>　　5、另外一个phuby</strong></p>
<p>　　Sean Huber也发布了另外一个同名的项目，居然也叫phuby，但这个跟上面介绍那个是完全没任何关系的。项目地址在https://github.com/huberry/phuby。这个项目为php增加了几个有趣的功能，而只需要在php中设置include_path指向phuby的库位置就可以了。虽然该项目还是处在比较初级的阶段，但其实它已经是综合了php和ruby的一些特点了。</p>
<p><strong>　　6、Objective-PHP and Moka</strong></p>
<p>　　Objective-PHP and Moka are two ambitious projects headed by Stephen Lerodiaconou. TObjective-PHP(https://github.com/stevegeek/moka)和Moka(https://github.com/stevegeek/moka)这两个项目是由Stephen Lerodiaconou.带领研发的很有野心的项目，他们为PHP语言增加了Object-C语言和Cocoa　framework(注：Cocoa是Mac OSX<a title="操作系统" href="http://product.pcpop.com/Operating_System/00000_1.html" target="_blank">操作系统</a>开发语言)。它们项目中的文档宣称这些新特性能吸引原来的Capucchino开发者。</p>
<p>　　你可以观看这个视频(http://vimeo.com/9838953)去了解这两个框架。</p>
<p><strong>　　7、Php-serial</strong></p>
<p>　　你想通过编写php语言去操纵如视频，音频或计算机的串并口设备?现在是可以变成现实了。使用php-serial这个开源项目(http://code.google.com/p/php-serial/)，可以很容易地去实现。比如只需要调用deviceSet()方法，将串口名传递进去就可以了，接着就可以使用简单的读和写的方法了，比如：</p>
<div id="div_code" style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 4px; width: 97%; word-break: break-all; padding-top: 4px; border: windowtext 0.5pt solid;">
<div><!--</p>
<p>Code highlighting produced by Actipro CodeHighlighter (freeware)</p>
<p>http://www.CodeHighlighter.com/</p>
<p>--><img src="http://www.wangchao123.com/CodeHighlighter/Images/OutliningIndicators/None.gif" alt="" align="top" /><span style="COLOR: #000000">&lt;?</span><span style="COLOR: #000000"><br />
<img src="http://www.wangchao123.com/CodeHighlighter/Images/OutliningIndicators/None.gif" alt="" align="top" />deviceSet(</span><span style="COLOR: #000000">&#8216;</span><span style="COLOR: #000000">COM2</span><span style="COLOR: #000000">&#8216;</span><span style="COLOR: #000000">);<br />
<img src="http://www.wangchao123.com/CodeHighlighter/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #800080">$seria</span><span style="COLOR: #000000">&#8211;&gt;</span><span style="COLOR: #000000">deviceOpen();<br />
<img src="http://www.wangchao123.com/CodeHighlighter/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #800080">$serial</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">sendMessage(</span><span style="COLOR: #000000">&#8216;</span><span style="COLOR: #000000">Sending a message to the port!</span><span style="COLOR: #000000">&#8216;</span><span style="COLOR: #000000">);<br />
<img src="http://www.wangchao123.com/CodeHighlighter/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #800080">$serial</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">deviceClose();<br />
<img src="http://www.wangchao123.com/CodeHighlighter/Images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="COLOR: #000000">?&gt;</span></div>
</div>
<p> <strong>　　8、Apns-PHP</strong></p>
<p>　　在苹果的操作系统3.0以上，你可以享受到苹果的推送信息的服务，简称Apple Push Notification Service(APNS)，及时获得各类有用的资讯。</p>
<p>　　现在，你可以使用PHP去实现这个功能了，apns-php项目提供了这个功能，项目的地址在http://code.google.com/p/apns-php/，该项目的文档宣称APNS API在2010年的12月17日已经完成了，可以提供自定义提醒图片和本地化的按钮等新特性。</p>
<p>　　有一篇很好的入门导学文章指导你对apns-php的学习(http://blog.boxedice.com/2009/07/10/how-to-build-an-apple-push-notification-provider-server-tutorial/)</p>
<p><strong>　　9、CFPropertyList</strong></p>
<p>　　cocoa框架使用属性列表来管理序列化数据。这些属性列表可以通过Apple的如plutil等工具进行设置。然而有的开发者希望用他们熟悉的方式去管理这些数据，目前有不少开源项目可以实现这个目的，比如CFPropertyList就是其中之一，项目地址在：</p>
<p>　　https://github.com/rodneyrehm/CFPropertyList，它允许PHP开发者可以创建属性列表，之后发送到iPhone应用。</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/03/21/677/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>50 个非常有用的PHP工具(转)</title>
		<link>http://www.wangchao123.com/2011/03/09/642</link>
		<comments>http://www.wangchao123.com/2011/03/09/642#comments</comments>
		<pubDate>Wed, 09 Mar 2011 03:28:26 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[开源软件]]></category>
		<category><![CDATA[性能优化]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=642</guid>
		<description><![CDATA[（版权属于原作者: http://www.javaeye.com/news/5208-50-very-useful-php-tools-editing-in） PHP是使用最为广泛的开源服务器端脚本语言之一，当然PHP并不是速度最快的，但它却是最常用的脚本语言。这里有50个有益的PHP工具，可以大大提高你的编程工作： 调试工具 Webgrind Xdebug Gubed PHP Debugger DBG PHP_Debug PHP_Dyn MacGDBp 测试和优化工具 PHPUnit SimpleTest Selenium PHP_CodeSniffer dBug PHP Profile Class 文档工具 phpDocumentor PHP DOX 安全工具 Securimage ：验证码工具。 Scavenger PHP-IDS Pixy ：代码检查工具。 图形处理 PHP/SWF Charts pChart &#8211; a chart-drawing PHP library WideImage MagickWand For PHP 代码优化 PHP_Beautifier PHPCodeBeautifier GeSHi &#8211; Generic Syntax Highlighter 版本控制系统 [...]]]></description>
			<content:encoded><![CDATA[<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;"><span style="font-size: small;">（版权属于原作者: <a href="http://www.javaeye.com/news/5208-50-very-useful-php-tools-editing-in">http://www.javaeye.com/news/5208-50-very-useful-php-tools-editing-in</a>）</p>
<p>PHP是使用最为广泛的开源服务器端脚本语言之一，当然PHP并<a style="color: #006699; text-decoration: underline;" href="http://izumi.plan99.net/blog/index.php/2008/01/17/ruby-vs-php-performance/">不是速度最快</a>的，但它却是<a style="color: #006699; text-decoration: underline;" href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">最常用的脚本语言</a>。这里有50个有益的PHP工具，可以大大提高你的编程工作：</p>
<p></span></h3>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">调试工具</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://code.google.com/p/webgrind/">Webgrind</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://xdebug.org/index.php">Xdebug</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://gubed.mccabe.nu/">Gubed PHP Debugger</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.php-debugger.com/dbg/">DBG</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.php-debug.com/www/">PHP_Debug</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://sourceforge.net/projects/php-dyn/">PHP_Dyn</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.bluestatic.org/software/macgdbp/">MacGDBp</a></li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">测试和优化工具</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.phpunit.de/">PHPUnit</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.simpletest.org/">SimpleTest</a>
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.simpletest.org/"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/112850mg4.png" alt="Simpletest" width="349" height="152" /></a></p>
</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://selenium-rc.openqa.org/">Selenium</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://matrix.squiz.net/developer/tools/php_cs">PHP_CodeSniffer</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://dbug.ospinto.com/">dBug</a>
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://dbug.ospinto.com/"><br />
<img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/112850BeD.jpg" alt="" /><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.coderholic.com/php-profile-class/">PHP Profile Class</a></li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">文档工具</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://phpdoc.org/">phpDocumentor</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://phpdox.net/">PHP DOX</a></li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">安全工具</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.phpcaptcha.org/">Securimage</a> ：验证码工具。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="https://trac.anl.gov/scavenger/wiki/WikiStart">Scavenger</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://php-ids.org/">PHP-IDS</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://blog.evaria.com/2007/pixy-the-php-security-scanner/">Pixy</a> ：代码检查工具。<a style="color: #006699; text-decoration: underline;" href="http://www.phpchina.com/html/21/n-16721.html" target="_blank"></a></li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">图形处理</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.maani.us/charts4/">PHP/SWF Charts</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://pchart.sourceforge.net/index.php">pChart &#8211; a chart-drawing PHP library</a>
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://simplepie.org/"><br />
<img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/112850Xor.jpg" alt="" /><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://wideimage.sourceforge.net/wiki/MainPage">WideImage</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.magickwand.org/">MagickWand For PHP</a></li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">代码优化</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://pear.php.net/package/PHP_Beautifier">PHP_Beautifier</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.waterproof.fr/products/phpCodeBeautifier/">PHPCodeBeautifier</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://qbnz.com/highlighter/">GeSHi &#8211; Generic Syntax Highlighter</a></li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">版本控制系统</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://phing.info/trac/">Phing</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://code.google.com/p/xinc/">xinc</a></li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">有用的拓展，使用工具和类</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://simplepie.org/">SimplePie</a> ：PHP RSS 解析程序
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://simplepie.org/"><br />
<img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/112850JvX.jpg" alt="" /><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://htmlpurifier.org/">HTML Purifier</a> ：可以用来移除所有恶意代码(XSS)，而且还能确保你的页面遵循W3C的标准规范。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf">TCPDF</a> ：一个用于快速生成PDF文件的PHP5函数包。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.jonasjohn.de/lab/htmlsql.htm">htmlSQL</a> ：一个是你可以方便的对HTML和XML内容方便的使用类似SQL语句进行检索的PHP类。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://searchlightdigital.com/the-greatest-php-snippet-file-ever-using-quicktext-for-notepad">The Greatest PHP Snippet File Ever (Using Quicktext for Notepad++)</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://creole.phpdb.org/trac/">Creole</a> ：用PHP5编写， 是一个基于真正意义的OO的层，API接口以JDBC为基础。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.codeplex.com/PHPLinq">PHPLinq</a> ：<span>用SQL语法操作PHP数组。</span></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.xm1math.net/phpmathpublisher/">PHPMathPublisher</a>：作者是一位法国中学数学老师。
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.xm1math.net/phpmathpublisher/"><br />
<img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/112851TSL.gif" alt="" /><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.phpmyadmin.net/home_page/index.php">phpMyAdmin</a> ：可以通过互联网在线控制和操作MySQL。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.codeplex.com/PHPExcel">PHPExcel</a> ：相当强大的MS Office Excel 文档生成类库。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://p.horm.org/er/">Phormer</a> :一个轻量级，强大的PHP在线相册。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.xajaxproject.org/">xajax PHP Class	Library</a> :一个开源的<em>PHP</em> 类库，用来构建WEB上的<em>Ajax</em> 程序。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://phpuserclass.com/">PHP User Class</a> ：用户管理。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://gtk.php.net/">PHP-GTK</a> ：为了证明PHP是一种远远超越网络应用程序的有效的工具而开发的。使用<em>PHP-GTK</em>你可以建立独立的GUI（用户图形界面）应用程序。</li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">在线工具和资源</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://code.google.com/p/minify/">Minify!</a> ：使用 PHP5 开发的用于合并压缩 js/css 文件的应用程序。合并压缩之后的结果可通过 HTTP gzip/deflate 及一些相关头，优化客户端缓存。
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://code.google.com/p/minify/"><br />
<img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/112851DO1.jpg" alt="" /></a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://en.dklab.ru/lib/HTTP_StaticMerger/">HTTP_StaticMerger</a>：自动“合并”CSS和JavaScript文件。</li>
</ul>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.phpobjectgenerator.com/">PHP Object	Generator</a> ：一个开源的<em>PHP</em>代码生成器。它能够为你的PHP4/<em>PHP5</em>应用程序生成简洁和可测试的面向对象代码。<br />
<img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/1141422qB.jpg" alt="" /></p>
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.phpobjectgenerator.com/"><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.gotapi.com/php">gotAPI/PHP</a>
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.gotapi.com/php"></a></p>
<p><a style="color: #006699; text-decoration: underline;" href="http://www.gotapi.com/php"><img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/114142UnN.jpg" alt="" /></p>
<p></a><a style="color: #006699; text-decoration: underline;" href="http://www.gotapi.com/php"></a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.koders.com/">koders</a> :开放源代码搜索。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://pecl.php.net/">PECL</a> ：含有PHP 开发组提供的不同扩展库的信息。</li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">浏览器中的工具（Firefox插件）</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.firephp.org/">FirePHP</a> ：是基于<a style="color: #006699; text-decoration: underline;" href="http://www.ooso.net/index.php/archives/294">Firebug</a>的一个扩展，可以用来在Firebug的console中方便的输出php的调试信息又不影响php程序的正常运行。
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.firephp.org/"><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://phplangeditor.mozdev.org/">phpLangEditor</a> ：是一个用来翻译各种PHP变数的工具.
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://phplangeditor.mozdev.org/"><br />
<img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/114142ezm.jpg" alt="" /><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="https://addons.mozilla.org/en-US/firefox/addon/3505">PHP	Lookup</a> :是一个内置的搜索栏，以帮助您快速查找引用的PHP语法。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="https://addons.mozilla.org/en-US/firefox/addon/8984">PHP	Manual Search</a> ：一个方便的搜索栏，从您的Web浏览器中<a style="color: #006699; text-decoration: underline;" href="http://www.php.net/docs.php">搜索官方PHP文档</a>。</li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">PHP框架</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://dwoo.org/">Dwoo</a> ：一个PHP5 的模板引擎。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://codeigniter.com/">CodeIgniter</a> ：帮助你编写Web 应用程序的敏捷开源PHP 框架。
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://codeigniter.com/"><br />
<img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/114142meZ.jpg" alt="" /><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.yiiframework.com/">YII Framework</a> 一个高性能的基于组件的PHP框架。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.solarphp.com/">Solar</a>
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.solarphp.com/"><br />
<img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/11414313v.jpg" alt="" /><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.symfony-project.org/">symfony</a> :一个开源的PHP Web框架。目的是加速Web应用的创建与维护。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://pear.php.net/">PEAR<br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://propel.phpdb.org/trac/">Propel</a> ：是一个适用于PHP5的OR映射(Object Relational Mapping)框架。它允许你使用对象代替SQL来读写数据库表格中的行。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://wiki.limb-project.com/doku.php?id=limb3:en:packages:macro">{{macro}} template engine<br />
<img style="border: 0px initial initial;" src="http://www.wangchao123.com/wp-content/uploads/auto_save_image/2011/03/114240CMQ.gif" alt="" /> </a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://framework.zend.com/">Zend Framework</a> ：<em> </em>是一个开放源代码的PHP5 开发框架，可用于来开发web 程序和服务。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.qcodo.com/">Qcodo</a> ：是一个适用于敏捷开发基于PHP5采用MVC架构与CRUD代码生成功能的框架。
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.qcodo.com/"><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.modernmethod.com/sajax/">SAJAX</a> ：Sajax 是一种制作 Ajax 应用程序的模块化方式，通过预定的、动态的函数调用，使得应用程序的开发过程更加平滑。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.smarty.net/">Smarty</a> : 用PHP实现MVC开发模式的逻辑层和表示层的模板引擎。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://cakephp.org/">CakePHP</a> ：是一个开源的PHP on rails的full-stack框架。
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://cakephp.org/"><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://phpsavant.com/yawiki/">Savant2</a> ：是一套直接使用PHP function，但是做了合理的限制的PHP模板引擎。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.phpspec.org/">PHPSpec</a> ：PHPSpec是一个简单而直观的PHP框架。</li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">IDEs 和 Editors</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.phpeclipse.com/">PHPEclipse</a> ：<span>相当强大的一个Eclipse下开发PHP的插件，包括的功能有：PHP语法分析,调试，代码格式化，大纲视图，代码模板定制等。</span>
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.phpeclipse.com/"><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.nusphere.com/products/phped.htm">PhpED</a> ：内部调试器。
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.nusphere.com/products/phped.htm"><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.mpsoftware.dk/phpdesigner.php">phpDesigner</a> ：针对PHP 网页的编写所设计的程序。
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.mpsoftware.dk/phpdesigner.php"><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.zend.com/en/products/studio/">Zend	Studio</a> ：一个屡获大奖的专业PHP 集成开发环境，具备功能强大的专业编辑工具和调试工具，支持PHP语法加亮显示。
<p style="padding: 0px; margin: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.zend.com/en/products/studio/"><br />
</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.aptana.com/php">Aptana PHP</a> :一个开源的IDE ,主要致力于浏览器端的开发。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.eclipse.org/pdt/">PDT</a> ：一个开发工具框架，致力于在Eclipse平台之上提供一个功能完整的PHP集成开发环境。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.jcxsoftware.com/vs.php">VS.Php</a> ：通过安装这个插件，我们可以在Visual Studio .Net这个市场中最流行的IDE中编译、编辑、配置PHP程序。</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.phpedit.com/">PHPEdit</a> :这款IDE软件提供用于突出语法显示、代码提示、代码识别，一个集成的PHP调试器以及一个帮助生成器工具。</li>
</ul>
<h3 style="font-size: 16px; line-height: 1.5em; margin-top: 0px; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; color: black; padding: 0px;">补充资源</h3>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding: 0px;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://code.google.com/p/phpfr/">PHP Function Reference</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://phpimpact.wordpress.com/2008/05/29/30-useful-php-classes-and-components/">30 Useful PHP Classes and Components</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://phpadvent.org/2008">PHP advent 2008</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.sitepoint.com/blogs/2008/05/13/useful-in-browser-development-tools-for-php/">Useful in-browser development tools for PHP</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://www.phpclasses.org/">PHPClasses.org</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://mashable.com/2007/09/26/php-toolbox/">PHP Developer’s Toolbox</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="https://trac.anl.gov/scavenger/wiki/WikiStart" target="_blank">Scavenger</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://php-ids.org/" target="_blank">PHP-IDS</a></li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding: 0px;"><a style="color: #006699; text-decoration: underline;" href="http://blog.evaria.com/2007/pixy-the-php-security-scanner/" target="_blank">Pixy: PHP Security Scanner</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/03/09/642/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iphone 开发文档，资源，入门索引</title>
		<link>http://www.wangchao123.com/2011/03/03/640</link>
		<comments>http://www.wangchao123.com/2011/03/03/640#comments</comments>
		<pubDate>Thu, 03 Mar 2011 05:49:48 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[iphone Mac 手机应用开发]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=640</guid>
		<description><![CDATA[引用新手入门页面    http://www.cocoachina.com/special/fornew.html 1.json json编码解码2.GTMBase64 base64编码解码3.TouchXML xml解析4.SFHFKeychainUtils 安全保存用户密码到keychain中5.MBProgressHUD 很棒的一个加载等待特效框架6.ASIHTTPRequest http等相关协议封装7.EGORefreshTableHeaderView 下拉刷新代码8.AsyncImageView 异步加载图片并缓存代码9.类似setting的竖立也分栏程序 1.下载排名相关:appannie2.用户行为分析:flurry3.majicrank-各国排名查询工具 (推荐)4.AppViz-App销售统计软件 (推荐)5.PodViz-用户评论等查看工具6.appfigures-报表统计分析工具7.我成立的一个帮助开发者推广app的评测站:苹果I派党]]></description>
			<content:encoded><![CDATA[<p>引用新手入门页面    <a href="http://www.cocoachina.com/special/fornew.html">http://www.cocoachina.com/special/fornew.html</p>
<p></a><br />
1.<a id="url_1" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://code.google.com/p/json-framework" target="_blank">json</a> json编码解码<br style="outline-style: none; outline-width: initial; outline-color: initial;" />2.<a id="url_2" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/?r=87" target="_blank">GTMBase64</a> base64编码解码<br style="outline-style: none; outline-width: initial; outline-color: initial;" />3.<a id="url_3" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="https://github.com/schwa/TouchXML" target="_blank">TouchXML</a> xml解析<br style="outline-style: none; outline-width: initial; outline-color: initial;" />4.<a id="url_4" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="https://github.com/ldandersen/scifihifi-iphone" target="_blank">SFHFKeychainUtils</a> 安全保存用户密码到keychain中<br style="outline-style: none; outline-width: initial; outline-color: initial;" />5.<a id="url_5" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="https://github.com/jdg/MBProgressHUD" target="_blank">MBProgressHUD</a> 很棒的一个加载等待特效框架<br style="outline-style: none; outline-width: initial; outline-color: initial;" />6.<a id="url_6" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://allseeing-i.com/ASIHTTPRequest" target="_blank">ASIHTTPRequest</a> http等相关协议封装<br style="outline-style: none; outline-width: initial; outline-color: initial;" />7.<a id="url_7" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="https://github.com/enormego/EGOTableViewPullRefresh" target="_blank">EGORefreshTableHeaderView</a> 下拉刷新<span id="rlt_3" style="outline-style: none; outline-width: initial; outline-color: initial; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #fa891b;">代码</span><br style="outline-style: none; outline-width: initial; outline-color: initial;" />8.<a id="url_8" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://www.markj.net/iphone-asynchronous-table-image/" target="_blank">AsyncImageView</a> 异步加载<span id="rlt_4" style="outline-style: none; outline-width: initial; outline-color: initial; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #fa891b;">图片</span>并缓存代码<br style="outline-style: none; outline-width: initial; outline-color: initial;" />9.<a id="url_9" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://blog.blackwhale.at/" target="_blank">类似setting的竖立也分栏程序</p>
<p>1.下载排名相关:</a><a id="url_10" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://www.appannie.com/" target="_blank">appannie</a><br style="outline-style: none; outline-width: initial; outline-color: initial;" />2.用户行为分析:<a id="url_11" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://www.flurry.com/" target="_blank">flurry</a><br style="outline-style: none; outline-width: initial; outline-color: initial;" />3.<a id="url_12" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://majicjungle.com/majicrank.html" target="_blank">majicrank</a>-各国排名查询工具 (推荐)<br style="outline-style: none; outline-width: initial; outline-color: initial;" />4.<a id="url_13" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://www.cocoachina.com/appstore/sales/2010/0331/890.html" target="_blank">AppViz</a>-App销售统计软件 (推荐)<br style="outline-style: none; outline-width: initial; outline-color: initial;" />5.<a id="url_14" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://www.ideaswarm.com/products/appviz/" target="_blank">PodViz</a>-用户评论等查看工具<br style="outline-style: none; outline-width: initial; outline-color: initial;" />6.<a id="url_15" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="https://www.appfigures.com/" target="_blank">appfigures</a>-报表统计分析工具<br style="outline-style: none; outline-width: initial; outline-color: initial;" />7.我成立的一个帮助开发者<span id="rlt_5" style="outline-style: none; outline-width: initial; outline-color: initial; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #fa891b;">推广</span><span id="rlt_1" style="outline-style: none; outline-width: initial; outline-color: initial; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #fa891b;">app</span>的评测站:<a id="url_16" style="outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; color: #0070af;" href="http://www.ipadown.com/" target="_blank">苹果I派党</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/03/03/640/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Android market 发布个人免费应用的步骤(转)</title>
		<link>http://www.wangchao123.com/2011/01/10/636</link>
		<comments>http://www.wangchao123.com/2011/01/10/636#comments</comments>
		<pubDate>Mon, 10 Jan 2011 11:25:26 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[手机]]></category>
		<category><![CDATA[推广]]></category>
		<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=636</guid>
		<description><![CDATA[参看这个网址，注册账户需要交钱，每年25美元。 http://www.hackvip.com/mobiwen/html/Mobile_218480.html   上传应用至Android Market需要先到以下账户注册Google Account https://www.google.com/accounts/NewAccount?continue=http://market.android.com/publish&#38;followup=http://market.android.com/publish&#38;service=androiddeveloper   再使用注册的Google Account注册登录Android Market https://www.google.com/accounts/ServiceLogin?service=androiddeveloper&#38;passive=true&#38;nui=1&#38;continue=http://market.android.com/publish&#38;followup=http://market.android.com/publish   按提示完成输入注册信息和付费过程，注意：注册过程中需要注册使用Google Checkout完成付费，使用信用卡。 完成Android Developer注册之后按一下教程完成程序上传 http://www.hackvip.com/mobiwen/html/Mobile_218480.html]]></description>
			<content:encoded><![CDATA[<p align="left">参看这个网址，注册账户需要交钱，每年25美元。</p>
<p align="left"><a href="http://www.hackvip.com/mobiwen/html/Mobile_218480.html">http://www.hackvip.com/mobiwen/html/Mobile_218480.html</a></p>
<p align="left"> </p>
<p>上传应用至Android Market需要先到以下账户注册Google Account</p>
<p><a href="https://www.google.com/accounts/NewAccount?continue=http://market.android.com/publish&amp;followup=http://market.android.com/publish&amp;service=androiddeveloper">https://www.google.com/accounts/NewAccount?continue=http://market.android.com/publish&amp;followup=http://market.android.com/publish&amp;service=androiddeveloper</a></p>
<p> </p>
<p>再使用注册的Google Account注册登录Android Market</p>
<p><a href="https://www.google.com/accounts/ServiceLogin?service=androiddeveloper&amp;passive=true&amp;nui=1&amp;continue=http://market.android.com/publish&amp;followup=http://market.android.com/publish">https://www.google.com/accounts/ServiceLogin?service=androiddeveloper&amp;passive=true&amp;nui=1&amp;continue=http://market.android.com/publish&amp;followup=http://market.android.com/publish</a></p>
<p> </p>
<p>按提示完成输入注册信息和付费过程，注意：注册过程中需要注册使用Google Checkout完成付费，使用信用卡。</p>
<p>完成Android Developer注册之后按一下教程完成程序上传</p>
<p><a href="http://www.hackvip.com/mobiwen/html/Mobile_218480.html">http://www.hackvip.com/mobiwen/html/Mobile_218480.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2011/01/10/636/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>php版push服务器的流程(测试成功)</title>
		<link>http://www.wangchao123.com/2010/12/30/627</link>
		<comments>http://www.wangchao123.com/2010/12/30/627#comments</comments>
		<pubDate>Thu, 30 Dec 2010 09:40:11 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[iphone Mac 手机应用开发]]></category>
		<category><![CDATA[手机]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=627</guid>
		<description><![CDATA[参考文档： http://www.cocoachina.com/bbs/read.php?tid-30410.html http://iphone.ipsw.info/2010/04/apple-push-notification-adhoc.html 初学iPhone开发,经过反复多次验证,结合下面2个教程: http://ameyashetti.wordpress.com/2009/07/31/apple-push-notification-service-tutorial/ http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/ 得出从零开始的php版push服务器搭建流程: ============================================================== 0.在Mac OS X机器上安装好XCode, 连接一台正常的iPhone, 保持平和的心态 APP 开发基础设置 1.在iPhone Provisioning Portal中建立好APP ID和Device. 2.在Keychain Access.app中生成证书请求CertificateSigningRequest.certSigningRequest(菜单 &#62; Keychain Access &#62; Certificate Assistant &#62; Request a Certificate From a Certificate Authority&#8230;). 3.在iPhone Provisioning Portal &#62; Certificates中请求一个证书(点击Request Certificate,上传CertificateSigningRequest.certSigningRequest). 4.请求完成后,将证书文件(developer_identity.cer)下载,双击导入到Key Chain中. 5.在iPhone Provisioning Portal &#62; Provisioning 中,新建一个Profile, 选择指定的APP ID和 Devices后生成. 6.将刚刚生成的Profile下载为*_profile.mobileprovision, 双击该文件, 将profile加载到iPhone中. [...]]]></description>
			<content:encoded><![CDATA[<p>参考文档：<br />
<a href="http://www.cocoachina.com/bbs/read.php?tid-30410.html">http://www.cocoachina.com/bbs/read.php?tid-30410.html</a><br />
<a href="http://iphone.ipsw.info/2010/04/apple-push-notification-adhoc.html">http://iphone.ipsw.info/2010/04/apple-push-notification-adhoc.html</a></p>
<p>初学<span id="rlt_1" style="cursor: pointer; border-bottom: #fa891b 1px solid;" onclick="sendmsg('pw_ajax.php','action=relatetag&amp;tagname=iPhone',this.id)">iPhone</span><span id="rlt_3" style="cursor: pointer; border-bottom: #fa891b 1px solid;" onclick="sendmsg('pw_ajax.php','action=relatetag&amp;tagname=开发',this.id)">开发</span>,经过反复多次验证,结合下面2个教程:<br />
<a id="url_1" onclick="return checkUrl(this)" href="http://ameyashetti.wordpress.com/2009/07/31/apple-push-notification-service-tutorial/" target="_blank"><span style="color: #0070af;">http://ameyashetti.wordpress.com/2009/07/31/apple-push-notification-service-tutorial/</span></a><br />
<a id="url_2" onclick="return checkUrl(this)" href="http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/" target="_blank"><span style="color: #0070af;">http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/</span></a></p>
<p>得出从零开始的php版push服务器搭建流程:<br />
==============================================================<br />
0.在Mac OS X机器上安装好<span id="rlt_5" style="cursor: pointer; border-bottom: #fa891b 1px solid;" onclick="sendmsg('pw_ajax.php','action=relatetag&amp;tagname=XCode',this.id)">XCode</span>, 连接一台正常的iPhone, 保持平和的心态</p>
<p><span id="rlt_2" style="cursor: pointer; border-bottom: #fa891b 1px solid;" onclick="sendmsg('pw_ajax.php','action=relatetag&amp;tagname=APP',this.id)">APP</span> 开发基础设置<br />
1.在iPhone Provisioning Portal中建立好APP ID和Device.<br />
2.在Keychain Access.app中生成证书请求CertificateSigningRequest.certSigningRequest(菜单 &gt; Keychain Access &gt; Certificate Assistant &gt; Request a Certificate From a Certificate Authority&#8230;).<br />
3.在iPhone Provisioning Portal &gt; Certificates中请求一个证书(点击Request Certificate,上传CertificateSigningRequest.certSigningRequest).<br />
4.请求完成后,将证书<span id="rlt_8" style="cursor: pointer; border-bottom: #fa891b 1px solid;" onclick="sendmsg('pw_ajax.php','action=relatetag&amp;tagname=文件',this.id)">文件</span>(developer_identity.cer)下载,双击导入到Key Chain中.<br />
5.在iPhone Provisioning Portal &gt; Provisioning 中,新建一个Profile, 选择指定的APP ID和 Devices后生成.<br />
6.将刚刚生成的Profile下载为*_profile.mobileprovision, 双击该文件, 将profile加载到iPhone中.</p>
<p>Push Notification service设置<br />
7.在iPhone Provisioning Portal &gt; App IDs,选择需要Push服务的App ID, 进入Configure.<br />
8.确认 Enable for <span id="rlt_6" style="cursor: pointer; border-bottom: #fa891b 1px solid;" onclick="sendmsg('pw_ajax.php','action=relatetag&amp;tagname=Apple',this.id)">Apple</span> Push Notification service ,配置 Development Push SSL Certificate, <span id="rlt_7" style="cursor: pointer; border-bottom: #fa891b 1px solid;" onclick="sendmsg('pw_ajax.php','action=relatetag&amp;tagname=上传',this.id)">上传</span>第2步生成的证书请求.<br />
9.下载生成的aps_developer_identity.cer, 完成Push服务配置.<br />
10.双击aps_developer_identity.cer,保存到Key Chain.</p>
<p>生成php Push Notification sender需要的证书文件<br />
11.在Keychain Access.app里选定这个新证书(Apple Development Push Services*),导出到桌面,保存为Certificates.p12.<br />
12.运行如下命令:</p>
<table border="0" cellspacing="0" cellpadding="0" width="80%">
<tbody>
<tr>
<td><span class="f10 s8"><a onclick="CopyCode(document.getElementById('code1'));" href="javascript:"><span style="color: #0070af;">复制代码</span></a></span></p>
<div id="code1" class="blockquote2">
<ol>
<li> openssl pkcs12 -clcerts -nokeys -out cert.pem -in Certificates.p12</li>
<li> openssl pkcs12 -nocerts -out key.pem -in Certificates.p12</li>
<li> openssl rsa -in key.pem -out key.unencrypted.pem</li>
<li> cat cert.pem key.unencrypted.pem &gt; ck.pem</li>
</ol>
</div>
</td>
</tr>
</tbody>
</table>
<p>获得php Push Notification sender所需的设备令牌:<br />
13.新建一个View-based Application项目,在$PROJECT_NAMEAppDelegate.m中:<br />
a.粘贴如下<span id="rlt_4" style="cursor: pointer; border-bottom: #fa891b 1px solid;" onclick="sendmsg('pw_ajax.php','action=relatetag&amp;tagname=代码',this.id)">代码</span>:</p>
<table border="0" cellspacing="0" cellpadding="0" width="80%">
<tbody>
<tr>
<td><span class="f10 s8"><a onclick="CopyCode(document.getElementById('code2'));" href="javascript:"><span style="color: #0070af;">复制代码</span></a></span></p>
<div id="code2" class="blockquote2">
<ol>
<li>- (void)applicationDidFinishLaunching:(UIApplication *)app {</li>
<li> // other setup tasks here….</li>
<li> [window addSubview:viewController.view];</li>
<li> [self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:@"Ok" otherButtonTitle:@""];</li>
<li> [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];</li>
<li>}</li>
<li>- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {</li>
<li> //NSLog(@”devToken=%@”,deviceToken);</li>
<li> [self alertNotice:@"" withMSG:[NSString stringWithFormat:@"devToken=%@",deviceToken] cancleButtonTitle:@”Ok” otherButtonTitle:@”"];</li>
<li>}</li>
<li>- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {</li>
<li> NSLog(@”Error in registration. Error: %@”, err);</li>
<li> [self alertNotice:@"" withMSG:[NSString stringWithFormat:@"Error in registration. Error: %@", err] cancleButtonTitle:@”Ok” otherButtonTitle:@”"];</li>
<li>}</li>
<li>-(void)alertNotice:(NSString *)title withMSG:(NSString *)msg cancleButtonTitle:(NSString *)cancleTitle otherButtonTitle:(NSString *)otherTitle{</li>
<li> UIAlertView *alert;</li>
<li> if([otherTitle isEqualToString:@""])</li>
<li> alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:nil,nil];</li>
<li> else</li>
<li> alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:otherTitle,nil];</li>
<li> [alert show];</li>
<li> [alert release];</li>
<li>}</li>
</ol>
</div>
</td>
</tr>
</tbody>
</table>
<p>b.在 &#8211; (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 方法中增加</p>
<table border="0" cellspacing="0" cellpadding="0" width="80%">
<tbody>
<tr>
<td><span class="f10 s8"><a onclick="CopyCode(document.getElementById('code3'));" href="javascript:"><span style="color: #0070af;">复制代码</span></a></span></p>
<div id="code3" class="blockquote2">
<ol>
<li> [self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:@"Ok" otherButtonTitle:@""];</li>
<li> [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];</li>
</ol>
</div>
</td>
</tr>
</tbody>
</table>
<p>14.项目设置<br />
a.Targets &gt; $APP_NAME &gt; context menu &gt; Properties &gt; Identifier<br />
修改 identifier 为App ID<br />
b.Targets &gt; $APP_NAME &gt; context menu &gt; Build &gt; Code Signing &gt; Code Signing Identifier &gt; Any iPhone OS Device<br />
指定 iPhone Developer 为开发用机<br />
15.编译并运行后会在iPhone上显示设备令牌</p>
<p>16.php Push Notification sender代码如下:</p>
<table border="0" cellspacing="0" cellpadding="0" width="80%">
<tbody>
<tr>
<td><span class="f10 s8"><a onclick="CopyCode(document.getElementById('code4'));" href="javascript:"><span style="color: #0070af;">复制代码</span></a></span></p>
<div class="blockquote2">
<p>exp:&lt;br&gt;<br />
?message=A test message from localhost&amp;badge=2&amp;sound=received5.caf&amp;deviceToken=xxx<br />
&lt;?<br />
$deviceToken = $_REQUEST['deviceToken'];<br />
//$deviceToken = &#8216;af21fc88 c3f5c90c f8ef8dc7 950f1101 37aab01c 169d5088 11af11cf 5dc617ee&#8217;;<br />
$pass = &#8217;111111&#8242;;   // Passphrase for the private key (ck.pem file)</p>
<p>// Get the parameters from http get or from command line<br />
$message = $_REQUEST['message'] or $message = $argv[1] or $message = &#8216;A test message from worldcup&#8217;;<br />
$badge = (int)$_REQUEST['badge'] or $badge = 0;<br />
$sound = $_REQUEST['sound'] or $sound = $argv[3];</p>
<p>// Construct the notification payload<br />
$body = array();<br />
$body['aps'] = array(&#8216;alert&#8217; =&gt; $message);<br />
if ($badge)<br />
$body['aps']['badge'] = $badge;<br />
if ($sound)<br />
$body['aps']['sound'] = $sound;</p>
<p>/* End of Configurable Items */<br />
$ctx = stream_context_create();<br />
stream_context_set_option($ctx, &#8216;ssl&#8217;, &#8216;local_cert&#8217;, &#8216;dev.pem&#8217;);<br />
// assume the private key passphase was removed.<br />
stream_context_set_option($ctx, &#8216;ssl&#8217;, &#8216;passphrase&#8217;, $pass);</p>
<p>// connect to apns<br />
$fp = stream_socket_client(&#8216;ssl://gateway.sandbox.push.apple.com:2195&#8242;, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);<br />
if (!$fp) {<br />
print “Failed to connect $err $errstr\n”;<br />
return;<br />
}<br />
else {<br />
print “Connection OK\n&lt;br/&gt;”;<br />
}</p>
<p>// send message<br />
$payload = json_encode($body);<br />
$msg = chr(0) . pack(“n”,32) . pack(&#8216;H*&#8217;, str_replace(&#8216; &#8216;, ”, $deviceToken)) . pack(“n”,strlen($payload)) . $payload;<br />
print “Sending message :” . $payload . “\n”;<br />
fwrite($fp, $msg);<br />
fclose($fp);<br />
?&gt;</p>
<ol>
<li><span style="color: #ff0000;">需要注意:</span><br />
dev 环境用:</li>
<li>$fp = stream_socket_client(“<span style="color: #ff0000;">ssl://gateway.sandbox.push.apple.com</span>:2195&#8243;, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);adhoc 用:<br />
$fp = stream_socket_client(“<span style="color: #ff0000;">ssl://gateway.push.apple.com</span>:2195&#8243;, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);</li>
</ol>
</div>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2010/12/30/627/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lnuix 命令</title>
		<link>http://www.wangchao123.com/2010/12/16/592</link>
		<comments>http://www.wangchao123.com/2010/12/16/592#comments</comments>
		<pubDate>Thu, 16 Dec 2010 09:40:21 +0000</pubDate>
		<dc:creator>wangchao</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.wangchao123.com/?p=592</guid>
		<description><![CDATA[watch -n1 free   监控内存]]></description>
			<content:encoded><![CDATA[<p>watch -n1 free   监控内存</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wangchao123.com/2010/12/16/592/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

