设为首页 收藏本站
查看: 297|回复: 0

[经验分享] PHP学习笔记(一)

[复制链接]

尚未签到

发表于 2017-3-20 12:27:53 | 显示全部楼层 |阅读模式
<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>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-352383-1-1.html 上篇帖子: PHP textarea换行 下篇帖子: 怎么学php
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表