Skip to content

Commit

Permalink
Update chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
mowangjuanzi committed Oct 23, 2023
1 parent 8c148f4 commit 9d23269
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 50 deletions.
10 changes: 4 additions & 6 deletions chapters/intro.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: f92fc517966b7efcc3e7f140ec5a117184d0422d Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: gregory, Luffy -->
<!-- EN-Revision: ba36a88377878340feb08b36cdde88c26f34df6a Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: gregory, Luffy, mowangjuanzi -->
<chapter xml:id="introduction" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>简介</title>

Expand Down Expand Up @@ -125,10 +125,8 @@
PEAR 库)仅使用 OOP 代码来开发。PHP 5 弥补了 PHP 4 的这一弱点,引入了完全的对象模型。
</para>
<para>
使用 PHP,并不局限于输出 HTML。PHP
还能被用来动态输出图像、PDF 文件甚至 Flash 动画(使用 libswf 和
Ming)。还能够非常简便的输出文本,例如 XHTML
以及任何其它形式的 XML 文件。PHP
使用 PHP,并不局限于输出 HTML。PHP 的能力还包含输出富文本类型,比如图像或者 PDF
文件、加密数据和发送邮件。还能够非常简便的输出文本,例如 JSON 或 XML。PHP
能够自动生成这些文件,在服务端开辟出一块动态内容的缓存,可以直接把它们打印出来,或者将它们存储到文件系统中。
</para>
<para>
Expand Down
95 changes: 51 additions & 44 deletions chapters/tutorial.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 528bcc7b2e73270c61b654a4ee50992808b128b5 Maintainer: HonestQiao Status: ready -->
<!-- EN-Revision: 46ffb4b3fa11ea5733de780a8bcc211d8dc3d92b Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: Gregory, Luffy, mowangjuanzi -->
<chapter xml:id="tutorial" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<info><title>简明教程</title></info>
Expand Down Expand Up @@ -56,18 +56,19 @@
<para>
<example>
<info><title>第一个 PHP 脚本:<filename>hello.php</filename></title></info>
<programlisting role="php">
<programlisting role="php">
<![CDATA[
<!DOCTYPE html>
<html>
<head>
<title>PHP 测试</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
]]>
</programlisting>
</programlisting>
<simpara>
在浏览器的地址栏里输入 web 服务器的 URL
访问这个文件,在结尾加上“/hello.php”。如果本地开发,那么这个
Expand All @@ -76,18 +77,19 @@
web 服务器的设置。如果所有的设置都正确,那么这个文件将被
PHP 解析,浏览器中将会输出如下结果:
</simpara>
<screen role="html">
<screen role="html">
<![CDATA[
<!DOCTYPE html>
<html>
<head>
<title>PHP 测试</title>
</head>
<body>
<p>Hello World</p>
</body>
<head>
<title>PHP Test</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>
]]>
</screen>
</screen>
</example>
</para>
<para>
Expand Down Expand Up @@ -195,7 +197,9 @@ echo $_SERVER['HTTP_USER_AGENT'];
该脚本的输出可能是:
</para>
<screen role="html">
<![CDATA[
Mozilla/5.0 (Linux) Firefox/112.0
]]>
</screen>
</example>
</para>
Expand All @@ -215,23 +219,23 @@ Mozilla/5.0 (Linux) Firefox/112.0
<para>
<example>
<info><title><link linkend="language.control-structures">流程控制</link>与<link linkend="language.functions">函数</link>的使用</title></info>
<programlisting role="php">
<programlisting role="php">
<![CDATA[
<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) {
echo 'You are using Firefox.<br />';
if (str_contains($_SERVER['HTTP_USER_AGENT'], 'Firefox')) {
echo 'You are using Firefox.';
}
?>
]]>
</programlisting>
</programlisting>
<para>
该脚本的输出可能是:
</para>
<screen role="html">
<screen role="html">
<![CDATA[
You are using Firefox.<br />
You are using Firefox.
]]>
</screen>
</screen>
</example>
</para>
<para>
Expand All @@ -242,14 +246,13 @@ You are using Firefox.<br />
linkend="langref">语言参考</link>”一章。
</para>
<para>
需要介绍的第二个原理,是对 <function>strpos</function>
函数的调用。<function>strpos</function> 是 PHP
的一个内置函数,其功能是在一个字符串中搜索另外一个字符串。例如我们现在需要在
需要介绍的第二个原理,是对 <function>str_contains</function>
函数的调用。<function>str_contains</function> 是 PHP
的一个内置函数,其功能是确定指定字符串是否包含其它字符串。例如我们现在需要在
<varname>$_SERVER['HTTP_USER_AGENT']</varname>(即所谓的 haystack)变量中寻找
<literal>'Firefox'</literal>。如果在这个 haystack
中该字符串(即所谓的 needle)被找到(“草里寻针”),则函数返回 needle
在 haystack 中相对于开头的位置;如果没有,则返回 &false;。如果该函数没有返回
&false;,则 <link linkend="control-structures.if">if</link> 会将条件判断为
中该字符串(即所谓的 needle)被找到(“草里寻针”),则函数返回 &true;;如果没有,则返回
&false;。如果返回 &true;,则 <link linkend="control-structures.if">if</link> 会将条件判断为
&true; 并运行其花括号 {} 内的代码;否则,则不运行这些代码。可以自己尝试利用
<link linkend="control-structures.if">if</link>,<link
linkend="control-structures.else">else</link> 以及其它的函数如
Expand All @@ -264,38 +267,38 @@ You are using Firefox.<br />
<para>
<example>
<info><title>混和 HTML 和 PHP 模式</title></info>
<programlisting role="php">
<programlisting role="php">
<![CDATA[
<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) {
if (str_contains($_SERVER['HTTP_USER_AGENT'], 'Firefox')) {
?>
<h3>strpos() must have returned non-false</h3>
<h3>str_contains() returned true</h3>
<p>You are using Firefox</p>
<?php
} else {
?>
<h3>strpos() must have returned false</h3>
<h3>str_contains() returned false</h3>
<p>You are not using Firefox</p>
<?php
}
?>
]]>
</programlisting>
</programlisting>
<para>
该脚本的输出可能是:
</para>
<screen role="html">
<screen role="html">
<![CDATA[
<h3>strpos() must have returned non-false</h3>
<h3>str_contains() returned true</h3>
<p>You are using Firefox</p>
]]>
</screen>
</screen>
</example>
</para>
<para>
和使用 PHP echo 语句输出不同的是,以上示例跳出了 PHP 模式直接发送
HTML。这里需要特别注意的一点是脚本的逻辑流保持不变。根据
<function>strpos</function> 的结果,只会有一个 HTML
<function>str_contains</function> 的结果,只会有一个 HTML
块将发送给浏览者。换句话说,取决于是否找到字符串 <literal>Firefox</literal>。
</para>
</section>
Expand All @@ -312,15 +315,19 @@ if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) {
<para>
<example>
<info><title>一个简单的 HTML 表单</title></info>
<programlisting role="html">
<programlisting role="html">
<![CDATA[
<form action="action.php" method="post">
<p>姓名: <input type="text" name="name" /></p>
<p>年龄: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
<label for="name">Your name:</label>
<input name="name" id="name" type="text">
<label for="age">Your age:</label>
<input name="age" id="age" type="number">
<button type="submit">Submit</button>
</form>
]]>
</programlisting>
</programlisting>
</example>
</para>
<para>
Expand Down

0 comments on commit 9d23269

Please sign in to comment.