`
gowithbutton
  • 浏览: 43477 次
社区版块
存档分类
最新评论

PHP学习笔记(一)

阅读更多

    <span style="font-family: 'Times New Roman'; font-size: 16px;"></span><div style="font-family: Arial; margin-top: 1px; margin-right: 4px; margin-bottom: 2px; margin-left: 2px; background-color: rgb(255, 255, 255); line-height: 1.6; font-size: 14px;">

<h2 style="font-weight: bold; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 14px;">学习和使用JAVA已经超过5年的时间了,现在准备以JAVA为基础学习PHP语言,主要从PHP和JAVA的区别方面入手进行学习</h2>
<div><br>
<div>
<span style="font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(249, 249, 249);"></span><h2 style="font-weight: bold; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 14px;">什么是 PHP?</h2>
<ul style="margin-top: 10px; margin-bottom: 0px;">
<li style="margin-top: 3px;">PHP 指 PHP:超文本预处理器(译者注:PHP: Hypertext Preprocessor,递归命名)</li>
<li style="margin-top: 3px;">PHP 是一种服务器端的脚本语言,类似 ASP</li>
<li style="margin-top: 3px;">PHP 脚本在服务器上执行</li>
<li style="margin-top: 3px;">PHP 支持很多数据库(MySQL、Informix、Oracle、Sybase、Solid、PostgreSQL、Generic ODBC 等等)</li>
<li style="margin-top: 3px;">PHP 是一个开源的软件(open source software,OSS)</li>
<li style="margin-top: 3px;">PHP 可免费下载使用</li>
</ul>
<span style="font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(249, 249, 249);"></span><h2 style="font-weight: bold; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 14px;">什么是 PHP 文件?</h2>
<ul style="margin-top: 10px; margin-bottom: 0px;">
<li style="margin-top: 3px;">PHP 文件可包含文本、HTML 标签以及脚本</li>
<li style="margin-top: 3px;">PHP 文件向浏览器返回纯粹的 HTML</li>
<li style="margin-top: 3px;">PHP 文件的文件后缀是 ".php"、".php3" 或 ".phtml"</li>
</ul>
<br>

<div><br>
<h2 style="font-weight: bold; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 14px;">PHP和JAVA的区别</h2>
<div>
<span style="font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(249, 249, 249);"></span><h2 style="font-weight: bold; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 14px;">区别一:基本的 PHP 语法</h2>
<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;">PHP 的脚本块以<?php开始,以?>结束。您可以把 PHP 的脚本块放置在文档中的任何位置。

<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;">不过,为了达到最好的兼容性,我们推荐您使用标准形式 (<?php),而不是简写形式。
<?php

?></pre>
<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;">PHP 文件通常会包含 HTML 标签,就像一个 HTML 文件,以及一些 PHP 脚本代码。

<pre style="width: 580px; margin-top: 10px; margin-bottom: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(119, 136, 85); border-right-color: rgb(119, 136, 85); border-bottom-color: rgb(119, 136, 85); border-left-color: rgb(119, 136, 85); background-color: rgb(245, 245, 245); font-family: 'Courier New', monospace; font-size: 12px;"><html>
<body>

<?php
echo "Hello World";
?>

</body>
</html></pre>
<br>

<div><br>
<h2 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 14px;">区别二:PHP 中的变量</h2>
<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;"><span style="font-weight: normal;">变量用于存储值,比如数字、文本字符串或数组。</span>

<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;"><span style="font-weight: normal;">PHP 中的所有变量都是以 $ 符号开始的。</span>

<pre style="width: 580px; margin-top: 10px; margin-bottom: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(119, 136, 85); border-right-color: rgb(119, 136, 85); border-bottom-color: rgb(119, 136, 85); border-left-color: rgb(119, 136, 85); background-color: rgb(245, 245, 245); font-family: 'Courier New', monospace; font-size: 12px;"><span style="font-weight: normal;">$var_name = value;</span></pre>
<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;"><span style="font-weight: normal;">PHP 的入门者往往会忘记在变量的前面的 $ 符号。如果那样做的话,变量将是无效的。</span>
<h2 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 14px;"><br></h2>区别三:PHP 是一门松散类型的语言(Loosely Typed Language)
<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;">在上面的例子中,您看到了,不必向 PHP 声明该变量的数据类型。

<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;">在强类型的编程语言中,您必须在使用前声明变量的类型和名称。

<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;"><br>

<h2 style="font-weight: bold; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 14px;">foreach 语句</h2>


<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;">foreach 语句用于循环遍历数组。

<h3 style="font-weight: bold; margin-top: 20px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px;">语法</h3>
<pre style="width: 580px; margin-top: 10px; margin-bottom: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(119, 136, 85); border-right-color: rgb(119, 136, 85); border-bottom-color: rgb(119, 136, 85); border-left-color: rgb(119, 136, 85); background-color: rgb(245, 245, 245); font-family: 'Courier New', monospace; font-size: 12px;">foreach (array as value)
{
    code to be executed;
}
</pre>
<h3 style="font-weight: bold; margin-top: 20px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px;">例子</h3>
<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;">下面的例子示范了一个循环,这个循环可以输出给定数组的值:
<html>
<body>

<?php
$arr=array("one", "two", "three");

foreach ($arr as $value)
{
  echo "Value: " . $value . "<br />";
}
?>

</body>
</html></pre>
<div style="font-family: Arial; margin-top: 1px; margin-right: 4px; margin-bottom: 2px; margin-left: 2px; background-color: rgb(255, 255, 255); line-height: 1.6; font-size: 14px;"><br>
<div style="font-family: Arial; margin-top: 1px; margin-right: 4px; margin-bottom: 2px; margin-left: 2px; background-color: rgb(255, 255, 255); line-height: 1.6; font-size: 14px;"><br>
<span style="font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(249, 249, 249);"></span><h2 style="font-weight: bold; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 14px;">创建 PHP 函数</h2>
<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;">函数是一种可以在任何被需要的时候执行的代码块。
<h3 style="font-weight: bold; margin-top: 20px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px;">创建 PHP 函数:</h3>

    <li style="margin-top: 3px;">所有的函数都使用关键词 "function()" 来开始</li>
    <li style="margin-top: 3px;">命名函数 - 函数的名称应该提示出它的功能。函数名称以字母或下划线开头。</li>
    <li style="margin-top: 3px;">添加 "{" - 开口的花括号之后的部分是函数的代码。</li>
    <li style="margin-top: 3px;">插入函数代码</li>
    <li style="margin-top: 3px;">添加一个 "}" - 函数通过关闭花括号来结束。</li>

<h3 style="font-weight: bold; margin-top: 20px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px;">例子</h3>

<pre style="width: 580px; margin-top: 10px; margin-bottom: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(119, 136, 85); border-right-color: rgb(119, 136, 85); border-bottom-color: rgb(119, 136, 85); border-left-color: rgb(119, 136, 85); background-color: rgb(245, 245, 245); font-family: 'Courier New', monospace; font-size: 12px;"><html>
<body>

<?php
function writeMyName()
  {
  echo "David Yang";
  }

writeMyName();
?>

</body>
</html></pre>
<br><span style="font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(249, 249, 249);"></span>

<h2 style="font-weight: bold; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 14px;">PHP 函数 - 返回值</h2>
<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;">函数也能用于返回值。
<h3 style="font-weight: bold; margin-top: 20px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px;">例子</h3>
<html>
<body>

<?php
function add($x,$y)
  {
  $total = $x + $y;
  return $total;
  }

echo "1 + 16 = " . add(1,16);
?>

</body>
</html></pre>
<p style="margin-top: 12px; margin-bottom: 0px; line-height: 18px;">以上代码的输出:
<pre style="width: 580px; margin-top: 10px; margin-bottom: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-color: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: rgb(119, 136, 85); border-right-color: rgb(119, 136, 85); border-bottom-color: rgb(119, 136, 85); border-left-color: rgb(119, 136, 85); background-color: rgb(245, 245, 245); font-family: 'Courier New', monospace; font-size: 12px;">1 + 16 = 17</pre>

 
0
0
分享到:
评论

相关推荐

    PHP个人学习笔记

    PHP个人学习笔记

    PHP学习笔记、PHP实例

    ### PHP学习笔记与实例解析 #### 第一章:PHP高级语法与功能 ##### PHP的`date()`函数 `date()`函数是PHP中用于格式化日期和时间的强大工具。它可以将Unix时间戳转换成人类可读的日期和时间格式。这个函数有两个...

    当年我学PHP时整理的学习笔记

    综上所述,这份学习笔记是一个全面的PHP入门教程,涵盖了从基本语法、数据类型到高级特性的众多主题,对于想要学习PHP的新手来说是一份极其有用的资源。通过逐个学习和实践这些文件中的内容,读者可以逐步建立起自己...

    php框架学习笔记.doc

    PHP框架学习笔记 PHP框架学习笔记是学习PHP框架的重要笔记,涵盖了CI框架的基本概念、控制器、模型、视图、URI路由、数据库操作、表单提交、上传文件、Session管理等方面的知识点。 CI框架的业务流程是从域名或...

    php100学习笔记

    根据提供的“php100学习笔记”的部分内容,我们可以总结出一系列重要的PHP知识点,涉及字符串处理、文件操作、类与对象的基础等内容。 ### 字符串处理 #### `str_replace` `str_replace`函数用于在字符串中替换...

    php学习笔记

    【PHP学习笔记】 在深入PHP之前,我们先回顾一下HTML的一些基础知识点。`&lt;hr&gt;`标签用于在HTML页面中创建一条水平线,起到分隔内容的作用。`target="_blank"`属性用于链接,当点击链接时会在新窗口打开目标页面。在...

    php学习笔记总结

    ### PHP学习笔记总结 #### 一、Trim() 函数 - **功能**:Trim() 函数用于删除字符串开头和结尾的空白字符(如空格、制表符等)。这是一个非常实用的功能,在处理用户输入的数据时尤其有用,可以避免因为用户无意中...

    一个自己学习总结的php类学习笔记

    首先,类是对象的蓝图,它定义了一组属性(数据)和方法(操作)。类将相关的数据和行为组织在一起,形成一个独立的实体。例如,一个“Person”类可能包含"name"和"age"属性,以及"sayHello"和"birthday"方法。通过...

    PHP学习笔记

    php的学习笔记,环境配置、开发基础、问题解决

    php基本语法学习笔记

    这篇"php基本语法学习笔记"将引导我们深入理解PHP的核心概念和基础语法。通过博主杨梦在ITEYE博客上分享的文章链接(https://yangmeng.iteye.com/blog/1969617),我们可以获得关于PHP编程的实用知识。 首先,PHP...

    php基础学习笔记

    ### PHP基础学习笔记 #### 第一章:PHP + MySQL 基础入门 ##### Web 开发简介 在这一章节中,我们首先介绍了Web开发的基本概念及其工作原理。Web开发涉及创建和维护网站的过程,它包括前端开发(负责网站外观、...

    PHP学习笔记1

    本篇PHP学习笔记覆盖了PHP的基础语法、变量、数据类型、控制结构、函数、面向对象编程、错误处理、文件操作以及与数据库的交互等内容,为初学者提供了一个全面的学习框架。掌握这些知识点后,你可以开始构建自己的...

    PHP第一部分学习笔记

    在本系列的学习笔记中,我们将深入探讨PHP编程的基础知识,从环境配置到基本语法,再到数组类型和HTML交互。PHP是一种广泛使用的服务器端脚本语言,尤其适合于Web开发,可以嵌入到HTML中,为网页添加动态内容和交互...

    php学习笔记之重要知识点总结

    这份"php学习笔记之重要知识点总结"涵盖了PHP与MySQL的基础,旨在为学习者提供一个全面的指南。下面,我们将深入探讨这些核心概念。 首先,让我们从PHP的基础开始。PHP是一种服务器端的脚本语言,主要用于Web开发,...

    Redis全套学习笔记 (带章节目录) 完整版pdf

    本文是一篇关于Redis全套学习笔记的文章,主要介绍了Redis的基础知识、数据结构、持久化、集群、高可用、性能优化等方面的内容。通过本文的学习,读者可以全面掌握Redis的使用和应用,提高自己的技术水平和实践能力...

    Php学习笔记.docPhp学习笔记.docPhp学习笔记.doc

    《PHP学习笔记》 在IT领域,PHP是一种广泛使用的服务器端脚本语言,尤其适合Web开发。这篇笔记主要探讨了PHP的基本语法特性,包括它的无类型特性、continue语句的独特用法以及数组的处理。 首先,PHP是无类型的,...

    PHP学习笔记.rar

    【PHP学习笔记】是作者四个月学习PHP过程中积累的个人笔记,主要涵盖了HTML基础、CSS基础以及PHP基础等核心内容。这些笔记对于初学者来说是非常有价值的资源,因为它们以小案例的形式展示了各种知识点,便于理解和...

    php二次开发学习笔记

    学习笔记php二次开发学习笔记 php二次开发学习笔记 php二次开发学习笔记

Global site tag (gtag.js) - Google Analytics