Home  >  Article  >  Backend Development  >  Getting Started with PHP for Newbies to PHP (1)_PHP Tutorial

Getting Started with PHP for Newbies to PHP (1)_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 10:57:13914browse

PHP is a server-side scripting language that is easy to learn and use. With very little programming knowledge you can use PHP to build a truly interactive WEB site. This part of the article will make you familiar with PHP. It is impossible for me to miss anything, my purpose is only to allow you to quickly start your PHP programming.

1. First condition

You must first have a working web server that supports PHP. I assume that all PHP files on your server have the extension .php3.

2. PHP installation

Generate a file named test.php3 with the following content:

<ol class="dp-c"><li class="alt"><span><span><? phpinfo(); ?>  </span></span></li></ol>

Then open this file in your browser. Take a look at this page to see what options your PHP installation uses.

3. Syntax

As mentioned before, you can mix your PHP code and HTML code. So you have to have a way to differentiate between the two. Here are a few ways you can do it. You can pick whichever one you're most comfortable with and stick with it!

Separate the

from HTML Here are the methods you can use:

<ol class="dp-c">
<li class="alt"><span><span><? . . . ?>   </span></span></li>
<li><span><?php . . . ?>   </span></li>
<li class="alt"><span><script language=</span><span class="string">"php"</span><span>> . . . </script>   </span></li>
<li><span><% . . . %> </span></li>
</ol>

Statement

Like Perl and C, statements are separated by (;) in PHP. Those separate tags from HTML also indicate the end of a statement.

Comments

PHP supports C, C++ and Unix style comments:

<ol class="dp-c">
<li class="alt"><span><span class="comment">/* C,C++风格多行注释 */</span><span>   </span></span></li>
<li>
<span class="comment">// C++风格单行注释  </span><span> </span>
</li>
<li class="alt"><span># Unix风格单行注释 </span></li>
</ol>

Example: Hello, World!

With the knowledge we have learned, you can write the simplest program to output what is perhaps the most famous word in the programming world:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span class="tag-name">HTML</span><span class="tag">></span><span>   </span></span></li>
<li>
<span class="tag"><</span><span class="tag-name">HEAD</span><span class="tag">></span><span>   </span>
</li>
<li class="alt">
<span class="tag"><</span><span class="tag-name">TITLE</span><span class="tag">></span><span>   </span>
</li>
<li>
<span class="tag"><?</span><span>   </span></li><li class="alt"><span class="tag-name">echo</span><span> "Hello World!";   </span></li><li><span class="tag">?></span><span>   </span>
</li>
<li class="alt">
<span class="tag"></</span><span class="tag-name">TITLE</span><span class="tag">></span><span>   </span>
</li>
<li>
<span class="tag"></</span><span class="tag-name">HEAD</span><span class="tag">></span><span>   </span>
</li>
<li class="alt">
<span class="tag"><</span><span class="tag-name">BODY</span><span class="tag">></span><span>   </span>
</li>
<li>
<span class="tag"><</span><span class="tag-name">H1</span><span class="tag">></span><span>   </span>
</li>
<li class="alt"><span>First PHP page   </span></li>
<li>
<span class="tag"></</span><span class="tag-name">H1</span><span class="tag">></span><span>   </span>
</li>
<li class="alt">
<span class="tag"><</span><span class="tag-name">HR</span><span class="tag">></span><span>   </span>
</li>
<li>
<span class="tag"><?</span><span>   </span></li><li class="alt"><span>// Single line C++ style comment   </span></li><li><span>/*   </span></li><li class="alt"><span>printing the message   </span></li><li><span>*/   </span></li><li class="alt"><span>echo "Hello World!";   </span></li><li><span># Unix style single line comment   </span></li><li class="alt"><span class="tag">?></span><span>   </span>
</li>
<li>
<span class="tag"></</span><span class="tag-name">BODY</span><span class="tag">></span><span>   </span>
</li>
<li class="alt">
<span class="tag"></</span><span class="tag-name">HTML</span><span class="tag">></span><span> </span>
</li>
</ol>

1

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445779.htmlTechArticlePHP is a server-side scripting language that is easy to learn and use. With very little programming knowledge you can use PHP to build a truly interactive WEB site. And this part of the article will give you an idea of...
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