PHPPHP Basic

What is PHP? Write your fist PHP Program

What is PHP?

PHP is a programming language that you can use to write Web applications. A Web application can be anything from a simple “contact us” form through to a fully-fledged blogging system, online store, or forum system.

PHP is a server-side language


PHP is known as a server-side programming language. This means that it runs on the Web server. Most Web programming languages are server-side, but some, such as JavaScript, are client-side, which means they run on the Web browser.

What you’ll need


In order to start writing PHP scripts, you need access to a Web server running PHP. Your main options are:

  • Run PHP on your own computer: The easiest way to do this is to install a complete package like XAMPP. This contains the Apache Web server, along with PHP and the MySQL database engine, in one easy-to-install package. XAMPP is available for Windows, Mac OS X, and Linux. (A popular alternative on Windows is WampServer.)
  • Run your PHP scripts on your Web host: If you already have a Web hosting account that supports PHP then you can upload your PHP scripts via FTP and run them on the Web server. The advantage of this approach is that you don’t have to install anything; the disadvantage is that it’s slower to write and test your scripts.

Text Editor


To create your script, you’ll need to use a text editor program. you can use any editor like notepad, notepad++, sublime text  or other.

Write your First PHP Program


</p>
<p>&lt;?php echo &quot;Hello World&quot;; ?&gt;</p>
<p>

Note: you need to start and close tag when you write php code. echo use for show your text in the browser. Your browser show your text which you written within in the cotation ” ” 

Mix PHP code with HTML


<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;First PHP code with html&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;?php</p>
<p>echo &quot;Hello world.This is my First PHP program code&quot;;</p>
<p>?&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />

Copy and paste the script code listed above into a new document in your text editor, then save the file as hello.php in the document root folder — that is, the top level of your website — on your hard drive. If you’re not sure where your document root folder is then consult your Web server manual. Common locations include:

  • XAMPP on Windows: C:/Program Files/xampp/htdocs/
  • XAMPP on Linux: /opt/lampp/htdocs/
  • XAMPP on Mac OS X: /Applications/XAMPP/htdocs/

If you want to run the script on your Web hosting account rather than your own computer then you’ll need to upload the script using FTP instead.

Testing the script


Now you’re ready to run your script. To do this, open a Web browser, type the script’s URL into the browser’s address bar, and press Enter. If you’re running the Web server on your own computer then the URL will probably be:

http://localhost/hello.php

If, on the other hand, you’re running the script on a Web hosting account then you need to use something like:

http://www.example.com/hello.php

 

Good job. You completely learn your first your PHP code setup.

Tags

Maksud Masum

Professional Web Developer, Andorid Appplication Developer with App Inventor.

Leave a Reply

Adblock Detected

Please consider supporting us by disabling your ad blocker