<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.2" -->
<rss version="0.92">
<channel>
	<title>PHP CookBook 中文翻译 :)</title>
	<link>http://blog.phpman.info</link>
	<description></description>
	<lastBuildDate>Sun, 23 Dec 2007 11:06:16 +0000</lastBuildDate>
	<docs>http://backend.userland.com/rss092</docs>
	<language>en</language>
	
	<item>
		<title>12.12阅读RSS和Atom Feeds</title>
		<description>12.12.1问题
You want to retrieve RSS and Atom feeds and look at the items. This allows you to incorporate newsfeeds from

multiple web sites into your application.

你想要找回RSS和Atom feeds和考虑在这个items. 它允许你合并newsfeeds从多种web sites到你的应用程序

12.12.2解答
Use the MagpieRSS parser. Here's an example that reads the RSS feed for the php.announce mailing list:

使用这个MagpieRss 剖析器。这里是一个例子阅读Rss feed到这个php.annouce邮件发送清单


?php
require 'rss_fetch.inc';
$feed = 'http://news.php.net/group.php?group=php.announce&#38;format=rss';
$rss = ...</description>
		<link>http://blog.phpman.info/archives/211</link>
			</item>
	<item>
		<title>12.11处理编码内容</title>
		<description>12.11.1问题
PHP XML extensions use UTF-8, but your data is in a different content encoding.

PHP的XML延展名使用UTF-8。但是你的数据在一个不同的内容编码

12.11.2解答

Use the iconv library to convert it before passing it into an XML extension:

使用这个iconv library去转换它，到一个XML延展名


$utf_8 = iconv('ISO-8859-1', 'UTF-8', $iso_8859_1);


Then convert it back when you are finished:
然后转换它当你完成

12.11.3讨论
Character encoding is a major PHP 5 weakness. Fortunately, Unicode support is ...</description>
		<link>http://blog.phpman.info/archives/209</link>
			</item>
	<item>
		<title>12.10确认XML文件</title>
		<description>12.10.1问题

You want to make sure your XML document abides by a schema, such as XML Schema, RelaxNG, and DTDs.

你想要确认你的XML文件坚持一个计划。例如XML计划。RelaxNG.和DTDs

12.10.2解答

Use the DOM extension
使用这个DOM延展名

With existing DOM objects, call DOMDocument::schemaValidate( ) or DOMDocument::relaxNGValidate( ):

使用现有的DOM对象。调用DOMDocument::schemaVlidate()或者DOMDOcument::relaxNGValidate()


$file = 'address-book.xml';
$schema = 'address-book.xsd';
$ab = new DOMDocument
$ab-&#62;load($file);
if ($ab-&#62;schemaValidate($schema)) {
    print "$file is valid.\n";
} else {
    print "$file is invalid.\n";
}


If ...</description>
		<link>http://blog.phpman.info/archives/208</link>
			</item>
	<item>
		<title>12.9从XSLT Stylesheets 调用PHP函数</title>
		<description>12.9.1问题
You want to call PHP functions from within an XSLT stylesheet.

你想要调用PHP函数从一个XSLT stylesheet

12.9.2解答
Invoke the XSLTProcessor::registerPHPFunctions( ) method to enable this functionality
调用XSLTProcessor::registerPHPFunctions()方法到functionlity

$xslt = new XSLTProcessor();
$xslt-&#62;registerPHPFunctions();


And use the function( ) or functionString( ) function within your stylesheet:
然后使用这个function()或者functionString()函数和你的风格


&#60;xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:php="http://php.net/xsl"
    xsl:extension-element-prefixes="php"&#62;
&#60;xsl:template match="/"&#62;
    &#60;xsl:value-of select="php:function('strftime', '%c')" /&#62;
&#60;/xsl:template&#62;
&#60;/xsl:stylesheet&#62;


12.9.3讨论
XSLT parameters are great when you need to ...</description>
		<link>http://blog.phpman.info/archives/207</link>
			</item>
	<item>
		<title>12.8设置XSLT参数从PHP中</title>
		<description>12.8.1问题

You want to set parameters in your XSLT stylesheet from PHP.

你想要设置你的XSLT参数从PHP中

12.8.2解答
Use the XSLTProcessor::setParameter( ) method:

使用这个XSLTProcessor::setParameter()方法

// This could also come from $_GET['city'];
$city = 'San Francisco';
$dom  = new DOMDocument
$dom-&#62;load('address-book.xml');
$xsl  = new DOMDocument
$xsl-&#62;load('stylesheet.xsl');
$xslt = new XSLTProcessor();
$xslt-&#62;importStylesheet($xsl);
$xslt-&#62;setParameter(NULL, 'city', $city);
print $xslt-&#62;transformToXML($dom);


This code sets the XSLT city parameter to the value stored in the PHP variable ...</description>
		<link>http://blog.phpman.info/archives/205</link>
			</item>
	<item>
		<title>12.7转换XML为XSLT</title>
		<description>12.7.1问题

You have an XML document and an XSL stylesheet. You want to transform the document using XSLT and capture the

results. This lets you apply stylesheets to your data and create different versions of your content for

different media.

你有一个XML文件和一个XSL stylesheet， 你想要转换文件使用XSLT和capure这个结果。它将你应用你的数据和创造不同的

版本在不同的媒体

12.7.2解答
Use PHP's XSLT extension
使用PHP的XSLT延展名


// Load XSL template
$xsl = newDOMDocument;
$xsl-&#62;load('stylesheet.xsl');
// Create new XSLTProcessor
$xslt ...</description>
		<link>http://blog.phpman.info/archives/204</link>
			</item>
	<item>
		<title>12.6提取信息使用XPath</title>
		<description>12.6.1问题
You want to make sophisticated queries of your XML data without parsing the document node by node.

你想要制造一个查询在你的XML数据和分解这个文件网点

12.6.2解答

Use XPath.
使用XPath
XPath is available in SimpleXML:
XPath是简单的可利用的

?php
$s = simplexml_load_file('address-book.xml');
$emails = $s-&#62;xpath('/address-book/person/email');
foreach ($emails as $email) {
    // do something with $email
}

And in DOM:

然后在DOM

?php
$dom = new DOMDocument;
$dom-&#62;load('address-book.xml');
$xpath = new DOMXPath($dom);
$email = $xpath-&#62;query('/address-book/person/email');
foreach ($emails as $email) {
    // ...</description>
		<link>http://blog.phpman.info/archives/203</link>
			</item>
	<item>
		<title>12.5分解巨大的XML文件</title>
		<description>12.5.1问题
You want to parse a large XML document. This document is so large that it's impractical to use SimpleXML or DOM because you cannot hold the entire document in memory. Instead, you must load the document in one section at a time.

你想要分解一个巨大的XML文件。这个文件是非常大、不切实际的使用SimpleXML或者DOM.因为你不希望全部的文件在memory。代替。你必须装在文件在一个部分

12.5.2解答
Use the XMLReader extension:

使用这个XMLReader延长名


?php
$reader = new XMLReader();
$reader-&#62;open('card-catalog.xml');
/* Loop through ...</description>
		<link>http://blog.phpman.info/archives/202</link>
			</item>
	<item>
		<title>12.4分析复杂的XML文件</title>
		<description>12.4.1问题
You have a complex XML document, such as one where you need to introspect the document to determine its

schema, or you need to use more esoteric XML features, such as processing instructions or comments.

你有一个复杂的XML文件。例如在你需要的内部文件去测定它的计划。或者你需要使用很多深奥的XML性质。例如处理指示或者

注释

12.4.2解答

Use the DOM extension. It provides a complete interface to all aspects of the XML specification
使用这个DOM延展名。它规定一个完整的界面到所有XML规范


?php
$dom = ...</description>
		<link>http://blog.phpman.info/archives/201</link>
			</item>
	<item>
		<title>12.2在DOM产生XML</title>
		<description>12.2.1问题
You want to generate XML but want to do it in an organized way instead of using print and loops.

你想要产生XML。但是应该在一个organized路线代替使用print 和loops

12.2.2解答
Use the DOM extension to create a DOMDocument object. After building up the document, call DOMDocument::save(

) or DOMDocument::saveXML( ) to generate a well-formed XML document
使用这个DOM的延长区创造一个DOMDocument object、然后树立这个文件、调用DOMDocument::save()或者

DOMDocument::saveXML()去产生一个健康成型的文件

?php
// create a new document
$dom ...</description>
		<link>http://blog.phpman.info/archives/199</link>
			</item>
	<item>
		<title>12.1产生XML当作一个字符串</title>
		<description>12.1.1问题
You want to generate XML. For instance, you want to provide an XML version of your data for another program to

parse.

你想要产生XML。例如。你想要规定一个XML版本的数据解析其他程序

12.1.2解答
Loop through your data and print it out surrounded by the correct XML tags:
通过你的数据打印出正确的XML标签

?php
header('Content-Type: text/xml');
print '&#60;?xml version="1.0"?&#62;' . "\n";
print "&#60;shows&#62;\n";
$shows = array(array('name'     =&#62; 'Simpsons',
                     'channel'  =&#62; 'FOX',
                     'start'    =&#62; '8:00 ...</description>
		<link>http://blog.phpman.info/archives/198</link>
			</item>
	<item>
		<title>11.7存储适合的结果到一览表</title>
		<description>11.7.1问题
You need to collect statistics from log tables that are too large to efficiently query in real time.

你需要收集统计到巨大的表格可以迅速的查询
11.7.2解答
Create a table that stores summary data from the complete log table, and query the summary table to generate

reports in nearly real time.

在全部的表格里创建一个表格去存储主要数据，然后查询一览表去产生报告在瞬间

11.7.3讨论

Let's say that you are logging search queries that web site ...</description>
		<link>http://blog.phpman.info/archives/197</link>
			</item>
	<item>
		<title>11.6存储任意数据到公用存储器</title>
		<description>11.6.1问题
You want a chunk of data to be available to all web server processes through shared memory.

你想要将大量的服务器进行可利用的数据存储到公用存储器
11.6.2解答

Use the pc_Shm class shown in Example 11-3. For example, to store a string in shared memory, used

the pc_Shm::save( ) method, which accepts a key/value pair
使用这个Pc_Shm类例如在例子11-3，例如去存储字符串到公用存储器。使用这个pc_Shm::save()方法，哪个认可一

个key/value

?php
$shm = new pc_Shm();
$secret_code = 'land shark';
$shm-&#62;save('mysecret', $secret_code);


Another process ...</description>
		<link>http://blog.phpman.info/archives/196</link>
			</item>
	<item>
		<title>11.5存储Session到公用存储器</title>
		<description>11.5.1问题
You want to store session data in shared memory to maximize performance.

你想要存储session数据到公用存储器，以保持最佳状态

11.5.2解答

Use the pc_Shm_Session class shown in Example 11-3. For example:

使用这个pc_Shm_Session 类例如在例子11-3、例如

?php
$s = new pc_Shm_Session();
ini_get('session.auto_start') or session_start();

11.5.3讨论
As discussed in Recipe 11.4, the session module allows users to define their own session handling

methods. While this flexibility is most commonly used to ...</description>
		<link>http://blog.phpman.info/archives/195</link>
			</item>
	<item>
		<title>11.4将session存储到数据库</title>
		<description>
11.4.1问题
You want to store session data in a database instead of in files. If multiple web servers all have access to the same database, the

session data is then mirrored across all the web servers.
你想要存储session数据在一个数据库代替在文件里。如果多样化网络服务器都有权使用一样的数据库。这个session数据在这个DOS访问所有 web服务器
11.4.2解答
Use a class or a set of functions in conjunction with the session_set_save_handler( ) function to ...</description>
		<link>http://blog.phpman.info/archives/194</link>
			</item>
	<item>
		<title>11.3防止SESSION固定</title>
		<description>11.3.1问题
You want to make sure that your application is not vulnerable to session fixation attacks.

你想要确认你的应用软件不容易遭到攻击session可以抵御攻击

11.3.2解答
Require the use of session cookies without session identifiers appended to URLs, and generate a new session ID frequently:

命令使用session cookies和session 表示符附加到URLs，然后产生一个新的session ID


ini_set('session.use_only_cookies', true);
session_start();
if (!isset($_SESSION['generated'])
    &#124;&#124; $_SESSION['generated'] &#60; (time() - 30)) {
    session_regenerate_id();
    $_SESSION['generated'] = time();
}

11.3.3讨论
In this ...</description>
		<link>http://blog.phpman.info/archives/193</link>
			</item>
	<item>
		<title>11.2防止Session丢失</title>
		<description>11.2.1问题
You want make sure an attacker can't access another user's session
你想要确认攻击者不能访问其他使用者的session

11.2.2解答
Allow passing of session IDs via cookies only, and generate an additional session token that is passed via URLs. Only requests that

contain a valid session ID and a valid session token may access the session:

允许通过session IDs到唯一的cookies。然后产生一个另外的session表示通过URLs、唯一的请求包含一个有效的session ID和一个有效的session表示可以

访问这个session


?php
ini_set('session.use_only_cookies', true);
session_start();
$sat     = 'YourSpecialValueHere';
$tokenstr ...</description>
		<link>http://blog.phpman.info/archives/192</link>
			</item>
	<item>
		<title>11.1使用Session跟踪</title>
		<description>11.1使用Session跟踪

11.1.1问题
You want to maintain information about a user as she moves through your site
你想要维护使用者的信息移动到你的站点

11.1.2解答
Use the sessions module. The session_start( ) function initializes a session, and accessing an element in the auto-global $_SESSION array tells PHP to keep track of the corresponding variable:

使用者这个session模块。这个seesion_start()函数初始化一个session。然后访问一个元素在全局变量$_SESSION数组告诉PHP相应的变量


?php
session_start();
$_SESSION['visits']++;
print 'You have visited here '.$_SESSION['visits'].' times.';


11.1.3讨论
The session function ...</description>
		<link>http://blog.phpman.info/archives/191</link>
			</item>
	<item>
		<title>11.0介绍</title>
		<description>As web applications have matured, the need for statefulness has become a common requirement. Stateful web applications, meaning applications that keep

track of a particular visitor's information as he travels throughout a site, are now so common that they are taken for granted.

当中web软件应用成熟。它需要充满规定丰富的成为一个必要条件。规定web应用。意思是应用详细的访问者的信息当中一个地点，既然是一个共有的。它们认可
Given the prevalence of web applications that keep track ...</description>
		<link>http://blog.phpman.info/archives/190</link>
			</item>
	<item>
		<title>10.16程序：存储一个有线状图案装饰的留言板</title>
		<description>Storing and retrieving threaded messages requires extra care to display the threads in the correct order. Finding the children of each message and building the tree of message relationships can easily lead to a recursive web of queries. Users generally look at a list of messages and read individual messages ...</description>
		<link>http://blog.phpman.info/archives/189</link>
			</item>
	<item>
		<title>10.15访问一个数据库连接到你的程序</title>
		<description>10.15.1问题
You've got a program with lots of functions and classes in it, and you want to maintain a single database

connection that's easily accessible from anywhere in the program.

你拥有一个程序和许多函数和类在内。然后你想要支持一个单一的数据库连接它很容易无论何处在这个程序

10.15.2解答
Use a static class method that creates the connection if it doesn't exist and returns the connection (see

Example 10-40).

使用一个静态的类方法创造这个连接。如果它不存在然后返回这个连接(请看例子10-40)

?php
class DBCxn {
    // What ...</description>
		<link>http://blog.phpman.info/archives/188</link>
			</item>
	<item>
		<title>10.14 Caching 查询和结果</title>
		<description>10.14.1问题

You don't want to rerun potentially expensive database queries when the results haven't changed
你不想返回潜在的昂贵的数据库查询当这个结果不再改变

10.14.2解答
Use PEAR's Cache_Lite package. It makes it simple to cache arbitrary data. In this case, cache the

results of a SELECT query and use the text of the query as a cache key. Example 10-39 shows how to ...</description>
		<link>http://blog.phpman.info/archives/187</link>
			</item>
	<item>
		<title>10.12建立Query标题</title>
		<description>10.12.1问题
You want to construct an INSERT or UPDATE query from an array of field names. For example, you want to

insert a new user into your database. Instead of hardcoding each field of user information (such as

username, email address, postal address, birthdate, etc.), you put the field names in an array ...</description>
		<link>http://blog.phpman.info/archives/186</link>
			</item>
	<item>
		<title>10.11创造唯一的标识符</title>
		<description>10.11.1问题
You want to assign unique IDs to users, articles, or other objects as you add them to your database.

你想要分配唯一的IDs到使用者文章或者其他对象当作你增加他们到你的数据库

10.11.2解答
Use PHP's uniqid( ) function to generate an identifier. To restrict the set of characters in the identifier, pass it through md5( ), which returns a string containing only numerals and the ...</description>
		<link>http://blog.phpman.info/archives/185</link>
			</item>
	<item>
		<title>10.10调试错误信息</title>
		<description>10.10.1问题
You want access to information to help you debug database problems. For example, when a query fails, you want to see what error message the database returns.

你想要有权使用信息帮助你调试数据库的问题。例如当一个query失败。你想看到错误信息在这个数据库返回

10.10.2解答
Use PDO::errorCode( ) or PDOStatement::errorCode( ) after an operation to get an error code if the operation failed. The corresponding errorInfo( ) method returns ...</description>
		<link>http://blog.phpman.info/archives/184</link>
			</item>
	<item>
		<title>10.11创造唯一的标识符</title>
		<description>10.11.1问题
You want to assign unique IDs to users, articles, or other objects as you add them to your database.

你想要分配唯一的IDs到使用者文章或者其他对象当作你增加他们到你的数据库

10.11.2解答
Use PHP's uniqid( ) function to generate an identifier. To restrict the set of characters in the

identifier, pass it through md5( ), which returns a string containing only numerals and the letters ...</description>
		<link>http://blog.phpman.info/archives/183</link>
			</item>
	<item>
		<title>10.8使用一个Query找到返回行数</title>
		<description>10.8.1问题
You want to know how many rows a SELECT query returned, or you want to know how many rows were changed by an INSERT, UPDATE, or DELETE query.
你想要知道query返回多少行。或者你想知道多少行改变一个INSERT. UPDATE 或者DELECT去query
10.8.2解答
If you're issuing an INSERT, UPDATE, or DELETE with PDO::exec( ), the return value from exec( ) is the number of ...</description>
		<link>http://blog.phpman.info/archives/179</link>
			</item>
	<item>
		<title>10.7 重复有效查询</title>
		<description>10.7.1问题
You want to run the same query multiple times, substituting in different values each time.

你想要运行一样的查询语句取代不同的数值在每个时间

10.7.2解答
Set up the query with PDO::prepare( ) and then run it by calling execute( ) on the prepared statement

that prepare( ) returns. The placeholders in the query passed to prepare( ) are replaced with data by

execute( ...</description>
		<link>http://blog.phpman.info/archives/178</link>
			</item>
	<item>
		<title>10.6在SQL数据库修改数据</title>
		<description>10.6.1问题
You want to add, remove, or change data in an SQL database.
你想要在数据库里增加，移动或者修改数据

10.6.2解答
Use PDO::exec( ) to send an INSERT, DELETE, or UPDATE command, as shown in Example 10-14.
使用PDO::exec()去发送一个INSERT. DELETE或者UPDATE命令。例如在例子10-14

?php
$db-&#62;exec("INSERT INTO family (id,name) VALUES (1,'Vito')")
$db-&#62;exec("DELETE FROM family WHERE name LIKE 'Fredo'");
$db-&#62;exec("UPDATE family SET is_naive = 1 WHERE name LIKE 'Kay'");

You can also ...</description>
		<link>http://blog.phpman.info/archives/177</link>
			</item>
	<item>
		<title>10.5 找出每行的循环</title>
		<description>
10.5.1问题
You want a concise way to execute a query and retrieve the data it returns.
你想要一个简单的办法去执行一个查询和找回这个数据返回

10.5.2解答
Use fetchAll( ) to get all the results from a query at once, as shown in Example 10-13.

使用fetchAll()去获得所有的结果从一个查询。例如在例子10-13

?php
$st = $db-&#62;query('SELECT planet, element FROM zodiac');
$results = $st-&#62;fetchAll();
foreach ($results as $i =&#62; $result) {
   print "Planet $i is ...</description>
		<link>http://blog.phpman.info/archives/176</link>
			</item>
</channel>
</rss>
