search
HomeBackend DevelopmentPHP TutorialLearn PHP in one post Beginner's tutorial_PHP tutorial

Learn PHP in one post Beginner's tutorial_PHP tutorial

Jul 21, 2016 pm 03:44 PM
phponeGetting Started Tutoriallearnbeatnewbiesystemlength

一贴学会PHP

系统长度32678字节,除去标点,还可以打一万字,如果写满,那也不短了.但是…
本着,变态的简单,流畅到底的适合广大浮躁的MJJ们浏览的原则,我尽量精简的有效的实用的阐述PHP的学习之道.

本文适宜受众:
熟练HTML,但是对PHP等动态语言一无所知,却在用dedecms或discuz等php程序的人.
当然,还要你有想学PHP的兴趣.毕竟纵使再简单也需要学习的动力,兴趣无疑是最好的.
不熟悉电脑操作,绝对路径,相对路径等东西的请上火星.

前提准备:
态度:认真,细心,不浮躁.
时间:仅需两个小时,但是请注意两个小时的完全时间.不要抽空去干别的,因为在学习的时候一但中断,再回过头来难免有眼高手低之嫌,而本人为顶级PHP非专业级专业写手杜撰,无法系统化教学,一但中断回头再看本文将一无是处.所以请准备两个小时.我尽量使本文能在两个小时内让你对PHP有所得.
环境架设:①单机.②适合菜鸟使用的集成环境,③我推荐的软件:APMServ 下载地址 (PHP版本5.2.0)
为了防止有超级新新新人在环境架设这一块卡住,我先发了一个用APMServ架设环境的教程贴.点击查看.建设运营区.

开始之前的FAQ

Q:我认真学习两个小时以后能变成高手吗?
A::tu: 少跟我来YY,《一贴学会PHP》目的只在简单学会PHP!只能让你两个小时后大致了解PHP,有深入学习的基础.请不要抱有幻想,脚踏实地,步步为赢.看完后纵使不能成为高手,也会向高手迈进一步..
Q:我要用什么编辑器什么的东西吗?
A:本次教学仅仅是使用Macromedia Dreamweaver 8编辑.,编辑器不是必须品.文本还能做网页呢!
Q:你丫废话是不是太多了…
A:饿,那就马上开始.
————————————————————————————————————–

=============无耻的分割线=============

吃饭一:
one:标志性语言啊
html中开头结尾都有标签,整个html页的内容都包含在里面.
对应的在php中可以这么YY,他只有一个标签所有的东西都差入在php后面的位置.
行一:行二:一段PHP代码
行三:?>

其中所有的 可以换成 省去"php"~~~
自己动手项目:
DW新建,动态页,PHP,代码模式,删除所有内容,然后再里面打入及?>,然后回车,和前删除键几次,体验红色的处女快感!才几分钟就已经开始写PHP拉~厉害噶,高手也~

two:最简单的输出
不乖的人可能在上述"一点PHP代码"的位置打了东西,然后保存了之后打开看了一下,一片空白乃至错误…
因为PHP当然不是html,他是服务器语言,所谓服务器语言就是你开到这一页,然后服务器端按照规律解析成html再返回给你打开.比html多了一道服务器解析过程.
尝试如下代码:

echo ‘微笑着吃饭好帅啊'
?>

保存文件名为yy.php后打开,如前后缀默认当然是PHP,一定要在支持PHP的环境下打开才有效果.如果在此处遇到问题,请查看APMServ是否开启,开启后你保存的文件位置是否在APMServ 目录下www\htdocs 下.如果都对,那么看看浏览器地址是不是http://127.0.0.1:端口/yy.php

three:最常见的错误
再修改如上代码:

echo ‘微笑着吃饭好帅啊'
echo ‘真的好帅啊'
?>

保存打开后是不是会发现有错误?这是历史上最常见最白痴又最常见的php错误.
php是逐行解析的,注意"行"的理解.每一行末尾都需要加上“;”。。。是字母L右边一个。
我也很费解,更恼火的是没有纠错功能,一错就全部不能打开,好在出错会显示错在哪一行。

four:最重要的概念
上条代码加如“ ; ”后打开之后会发现显示效果“微笑着吃饭好帅啊真的好帅啊”粘在一起。
请右键查看源文件,你会发现原来源文件也是这样的。那怎么办呢?
php是一种可插入html的语言,也就是他可以把html给QJ掉。。。
理论上都可以插入到html中去。。。复制如下体验一下。。。
 

 

 

 

five:最重要的应用
到此处如果还没有动过一下手的,请劳驾动一下手吧,以上所有也才几分钟,但是却有一个重要的体验过程。
认真做过来的人会发觉,PHP这样子学了有个屁用?那么现在。。。我也不能告诉你有什么用,接着到此处变量了。
我尽量少使用术语,尽量通俗,但是变量这个词找不到替代品。但是很好理解的,接着看。

$chifan="123er";
echo $chifan;
?>

保存打开后,显示的内容是123er,那么熟悉html的很容易就想的到修改代码中""之间的123er就可以修改显示内容了吧!
没有错,而且理论上修改两个chifan,只要保持他们是一样的,也都可以显示。
这只有两行,第一行是定义变量chifan的值为123er,第二行就是显示变量chifan。就这么简单。
很容易的就学会了定义变量和显示变量的方法!

吃饭二:
经过《吃饭一》中简单有趣生动的学习,你是否觉得PHP其实一点都不难呢?但是你是否也开始担心PHP没有用处呢?
这一节详细介绍php的概念性的东西。
很明显的没有前一篇生动,这一段不是必须的,如果只是想了解一下而不打算学的完全可以跳过这一段. r />php函数:什么是函数?比如y=2x是个函数,那么,只要知道x就可以得出相应的y出来.php强大的函数库是其主要的彪悍功能之一,如专用于mysql的函数,那么只需要数据库名用户名密码就可以自由而简单的连接数据库.
php手册:记载php语法和函数的册子,因为不是人人都能牢记每个函数每个语法的.所以大部分人在用的时候都会有需要查询手册的时候.它的意义,打个浅显的比喻,如y=2x的函数,你不知道有这个函数你就得当做x+x来算一次,但是如果你知道有个y=2x的函数,你就只需要调用函数y,然后输入x就可以得出结果.对于php手册,建议抽空看了一次又看一次,不能牢记但是可以记得里面有哪些功能.也许x+x你可以自己写出来,但是更复杂的你不一定能写出来,就算写出来有点费力,所以越麻烦的问题调用现成函数的作用就越来越明显和必要.
自己写函数,函数的作用和意义如此强大,但总也有自己独特需求的函数,函数可以自己写,善于使用函数可以达到事半功倍的效果……废话这么多全是再理解函数,可见函数是多么的重要!
最后一个推荐或理解的比喻,几个实用的函数如时间调用函数,IP地址获取函数,可以在手册里找到,只需要简单的调用函数显示结果就可以很容易的得到想要定制的时间和IP地址.(还不明白我就无解了)
面对对象与面对过程:请百度或GG一下,感觉越来越离题…离简单之主题.
语法细节:
如: echo "哈哈"?> echo ‘哈哈'?>的区别(区别在哪?在于"")以及全角于半角的区别.“”‘'()()以及如何显示出""这些定义变量的东西等头疼问题!…我一想到就头痛.看到这来了肯定也很头痛.
全角和半角没有区别,功能相同.很完美.
如何显示语法的符号也不难,只需要在相应符号前加个 / 即可.不过看起来会很别扭.
双引和单引的区别在于双引会解析变量,而单引是直接显示.

$mjj = "哈哈" ;
echo $mjj;
echo "
" ;
echo "这是$mjj";
echo "
" ;
echo ‘这是$mjj';
?>

以下三个是常用语法的一个小补充.然后开始实习.
常量: define

   define("PAGE_TITLE", "MJJ的页面");
   define("PAGE_BODY", "MJJ就是木鸡鸡");

?>

<?php echo PAGE_TITLE ?>




更简单的输出 = ?>
如以上的title句可以换成:
= PAGE_TITLE ?>
页面调用require和include
2个都是调用其他页面,php是逐行翻译的,但是require是优先调用,include是读到这一行时翻译.
怎么运用调用的,是门大艺术.(怕出错require可以使用require_once只调用该页面一次)格式如下:
require_once ‘./include/286.php';
include ‘mjj.php';
自己建个286.php或mjj.php来调用玩一下吧.可以写成txt但是必须符合php语法.调用来当php用.

吃饭三:
实例:一行URL跳转代码

复制内容到剪贴板
Code:

<font face="新宋体"> $url=$_GET["url"];header("Location:"."http://".$url);?> </font>

If you save it as aaa.php, you can achieve the effect of aaa.php?url=www.baidu.com jumping to Baidu.
This simply calls the default $_GET variable. And php default jump Location :
(More default variables are in the manual)
Instance upgrade: Add if loop

Copy content to clipboard
Code:

<font face="新宋体"><code id="code1"><font face="新宋体"><br>$url=$_GET["url"];<br>if (strlen($url >= '3')){<br>header("Location:"."http://".$url);<br>}<br>?><br><br><br><title>URL转向页</title> <br><br><br><form id="url" name="url" method="get" action="#"> <br><label>http://<br><input name="url" type="text" value=""><br></label><br><input type="submit" name="Submit" value="提交"><br> </form> <br><br></font>$url=$_GET["url"];

if (strlen($url >= '3')) {

header("Location:"."http://".$url);
}

?>

< ;title>URL redirect page




< ;input type="submit" name="Submit" value="Submit" />

After talking so much, I have never talked about loops. I regard it as the most difficult content of this tutorial (to illustrate how easy it is to learn in one post~)
This upgrade code is very simple, that is, it can make this The jump page can also be opened. It will only jump when the URL address obtained is greater than 3.


Written after learning:

If you are inspired to learn PHP and feel that you have really started (read it again if you haven’t started yet), then there is
Two advanced methods.

For the robust type, you can first read through the PHP manual, and then start looking for examples in guestbooks, blogs, and BBS (in order, you can start with text and then mysql) and start remaking it step by step.
For those who are passionate, you can directly start looking for examples and follow them step by step. After you have some insights and feel lacking, you can supplement the PHP manual. There are too many examples on the Internet.

Improvement stage:

Understand the changes and differences of php4, php5, and php6. The main focus is on researching the current popular php programs. (Before this, you need to adapt to an editor. If possible, it is best to understand a certain framework. The outdated forum has published frameworks , see you in the code area.) The open source PHP program will bring you a brand new experience. If you understand it in the future, you can at least change it.

Advanced stage:

I am not qualified to introduce it yet. I hope everyone can become masters together.
Finally, I wish all friends who are interested in php can become masters!

————————————-Dividing line————————

Finally completed, not excluding loopholes, this article took a total of 4 hours + 3 hours. I hope it can be corrected Help from friends in need.

echo 'You are so handsome when you eat with a smile';echo 'You are so handsome';?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you create and use an interface in PHP?How do you create and use an interface in PHP?Apr 30, 2025 pm 03:40 PM

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

What is the difference between crypt() and password_hash()?What is the difference between crypt() and password_hash()?Apr 30, 2025 pm 03:39 PM

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

How can you prevent Cross-Site Scripting (XSS) in PHP?How can you prevent Cross-Site Scripting (XSS) in PHP?Apr 30, 2025 pm 03:38 PM

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

What is autoloading in PHP?What is autoloading in PHP?Apr 30, 2025 pm 03:37 PM

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

What are PHP streams?What are PHP streams?Apr 30, 2025 pm 03:36 PM

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

What is the maximum size of a file that can be uploaded using PHP ?What is the maximum size of a file that can be uploaded using PHP ?Apr 30, 2025 pm 03:35 PM

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

What is Nullable types in PHP ?What is Nullable types in PHP ?Apr 30, 2025 pm 03:34 PM

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

What is the difference between the unset() and unlink() functions ?What is the difference between the unset() and unlink() functions ?Apr 30, 2025 pm 03:33 PM

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment