Getting Started With PHP

PHP Tutorial: Get started with PHP from scratch

PHP is the ideal language for new developers. It is simple, fast, and intuitive. It is also very similar to other programming languages, like C, so you can pick other languages up faster with PHP knowledge.

Today we’ll get you started with PHP from the very beginning, breaking down what PHP is, why you should learn it, and some of its unique advantages. Then we’ll walk you through your first PHP “Hello World” program. Finally, we’ll cover the core PHP syntax and work through exercises.

By the end, you’ll have a solid foundation of basic PHP concepts and will be able to advance to intermediate topics. No prior knowledge of PHP is required, but to be successful in this tutorial, some general knowledge of programming will help you get the most from our exercises. For a quick introduction, , check out The Absolute Beginner’s Guide to Programming.

Here’s what we’ll cover today:

Читайте также:  Css img left right

Start your PHP career for free

Learn all the basics of PHP with developer-made lessons, tutorials, and quizzes, all free of charge.

What is PHP?

PHP is a recursive acronym for PHP: Hypertext Preprocessor. It is a popular, open source scripting language that is similar to C and especially suited for web development. PHP can be directly embedded into HTML using the instructions. These simple code instructions allow you to jump between HTML and PHP code without the need for extra commands used with C or Perl.

Another unique factor of PHP is that its code is executed on the server rather than client-side, or the side of the internet that a user sees. Once executed, PHP code generates HTML, which is then sent client-side. This makes PHP very secure and ensures that users cannot see what’s going on behind the screen.

Why should you learn PHP?

PHP is a great starting point for any new developer. PHP’s simplicity means it’s easier to pick up than other languages. Even if you don’t want to work in web development, the syntax and object-oriented thinking skills of PHP can give you a significant advantage when learning other OOP languages like Java or C++.

PHP also comes with a massive community. In fact, Github reports that PHP is the 5th most popular language in the world, PHP has the 3rd largest community on StackOverflow. This large community ensures you’ll never be without help if you get stuck.

Finally, PHP is a widely sought skill in the modern digital economy, and demand is growing. Popular sites like Facebook, Wikipedia, Yahoo, and Flickr are all built on PHP. In fact, data collected by Codementor found that PHP is used for 80% of the world’s top 10 million websites and about 40% of all sites on the internet!

PHP has also gained popularity as the go-to for small businesses. This is because intuitive content management systems like WordPress and Wix are written in PHP. A lot of PHP web developers are freelance workers who help launch new websites for businesses. The need for PHP developers is increasing.

What is PHP used for?

PHP is most often used in server-side web development. Thanks to server-side execution, PHP is great for dynamic web pages, a type of site which updates periodically or reacts to certain events. PHP’s secure function-hiding abilities also make it ideal for working with sensitive financial or personal information.

Online stores are a place we can see both of these strengths come into play. For example, PHP is used in the “shopping cart” functions of many sites. This is because PHP only sends the outcome of adding the item or completed transaction without giving access to the function.

Beyond this, PHP is also used in command-side scripting and graphical user interface design (GUI). PHP shows its value as a widely available and generalized language capable of running on nearly any operating system or database.

Advantages of PHP

  • Quick and Easy to Learn: PHP is beginner friendly and can be learned quickly relative to other languages. It’s also often considered a great first language.
  • Large Community: PHP has a large user base and online support community.
  • Widely Applicable: PHP can be used on any operating system or database.
  • Open Source: PHP is free to adopt and download along with all of its tools. This also means that the language is highly receptive to community feedback.
  • Great Performance: PHP uses its own memory space rather than an overhead server.

Источник

Getting Started with PHP Programming

PHP (Hypertext Preprocessor) is known as a general-purpose scripting language that can be utilized to create intuitive and dynamic websites. It was among the pioneer server-side language that can be integrated into HTML, making it easier to include functionality to web pages without requiring to call external data.

The demand of PHP is evident from the fact that the world’s top websites, like Facebook, Google, Wikipedia, and YouTube, are using PHP scripts at the backend. Before going towards the step-by-step guide on how to write PHP scripts, I will give you a general overview of PHP.

php guide

What is PHP?

First introduced by Rasmus Lerdorf, PHP is an open-source, server-side general scripting language that has now become a de-facto coding standard in the web development industry. It can be learned easily, and if one is from a coding background, he (or she) will find it very simple. This is why many are using PHP to polish up their entry-level coding skills.

PHP runs on different operating systems, like Windows, UNIX, Linux and supports different databases like MySQL, Microsoft Access, and Oracle. PHP can not only collect form data, but it can also create, read, write, delete, and close files on the server.

It can be easily embedded in HTML. PHP code is embedded in HTML with tags .

PHP is one of the easier programming languages to learn. PHP features a solid ecosystem of resources for beginners and it encompasses a syntax that is forgiving to beginners.

Host PHP Websites with Ease [Starts at $11 Credit]

Where to use PHP code?

You can use PHP to create dynamic web pages, collect form data, and send or receive cookies.

Applications of PHP Scripts

Let us see how many ways PHP scripting is used.

Server-Side Scripting

Server side scripting is the first purpose of PHP. All you need to start working on a desktop PC with PHP is a PHP Parser, a webserver (such as Apache) and a web browser like Google Chrome.

Command Line Scripting

If you want to use PHP programming on Linux or task scheduler on Windows, then you don’t really need a web server, but only a PHP Parser. This is called “command line scripting”.

Desktop Applications

Although, PHP is not a suitable language for development of desktop applications, but it supports some advanced features like PHP-GTK which is basically an extension of PHP. PHP-GTK provides object-oriented user interface.

PHP programming enables you to choose not only the operating system of your choice but also allows you to have choices to use a web server that you are familiar with. It also enables beginners and professionals to write scripts in their own ways as it allows procedural as well as object-oriented programming.

PHP not only enables you to output HTML but also lets you include images, PDFs, videos, and sounds. PHP can auto-generate XHTML and XML files.

PHP provides support to protocols like LDAP, HTTP, COM, POP3, etc. It also supports WDDX complex data exchange.

PHP IN PRACTICE: GETTING STARTED

You need few things to get started: a development environment to run your PHP code and a code editor to write the code.

  • Download and install the latest XAMPP for your preferred platform, be it a Linux, Mac, or Windows machine.
  • For an excellent code editor, I would recommend you download Sublime text 3 preferably.
  • Once you install the XAMPP apache web server and MySQL database comes along with it, from here, you can simulate from your PC or Mac a web server.

How to install PHP

Before you start using PHP, you need a web host with PHP and MYSQL. For this, you should also install a web server such as Apache. To do it locally on your PC, you may download XAMPP directly from Apache Friends .

Installation of Apache, PHP, MySQL, and PHPMyAdmin

In order to start PHP, MySQL, PHPMyAdmin and Apache in a single attempt, XAMPP should be installed.

Scroll over to XAMPP for Windows and download should begin shortly.

what is XAMPP

Click the .exe file to start the installation procedure.

setup xampp

Select the components which you want to install and click “Next”.

Xampp Server

In the components area, you can view several options. As a beginner, you don’t need all of them. You need to install Apache, which is a very famous web server. It manages client responses. For data storage and view, you need a database such as MySQL. Filezilla FTP server option is not needed for performing operations at localhost. Next option is the Mercury Mail Server option. Its primary function is to deal with emails received by the server. It is needed to enable the flow of emails, which is not a requirement at the moment. Tomcat is also a web server owned by Apache.

Stop Wasting Time on Servers Switch To Cloudways

We handle server management for you so you can focus on creating great apps and keeping your clients happy.

Coming down to programming languages, PERL (which is also a high-level programming language) is not a need at the moment. PhpMyAdmin is the admin panel of database and is needed. Webalizer is an application for analysis and you need to install it for monitoring purposes. Fake Sendmail is also an application that will be explained later.

Steps:

Select your desired location, where you want to install XAMPP and then click “Next”.

installation Xampp

Click “Next” on the coming screens to proceed with the installation process.

installation Xampp

Welcome Xampp

Now, you will see the final screen. I would suggest that you keep the “start the Control Panel” option checked. Click “Finish” to complete the installation process. A new window will open shortly.

Xampp setup wizard

The XAMPP Control Panel has now started. Now, click “Start” button in Apache and MySQL rows to begin.

Xampp Control Panel

Xampp Control Panel

You are now ready to start writing the code. Now all you need is an editor like Notepad++ or Dreamweaver to write the code.

After downloading Notepad++, you can start writing your code

Now, save the page as “test.php” in htdocs folder and click “Save” button.

test.php

Now, open a web browser and type localhost in the address bar. It will automatically open the index file but if you type localhost/test.php , it will open the page that we have saved.

my first php page



Beginners Guide For PHP

Tutorial Series For Learning PHP

echo “2+3″.”
”;//It will display the output 2+3
print “2+3”;// print will also display the output 2+3
?>

In this example, we use echo and print to show the same result. Here is the output we get.

beginners guide for PHP

You can see that the two lines of 2+3 are displayed as output by using different statements. Most of the professional programmers prefer to use echo because echo can bring up multiple strings or values at the same time, whereas print displays one statement at a time. Both echo and print can be used with or without parentheses; print() or echo() . Also, it is to be noticed that you can not see the sum of two numbers without using variables. The concept of variables will be introduced along with PHP data types in the next tutorial.

Consider the example below.



Beginners Guide For PHP

Tutorial Series For Learning PHP

$a=99;
$b=”Calculus”;
echo “Numbers you have got in $b are $a”.”
”;
echo ‘Numbers you have got in $b are $a’;
?>

In this example, you can see that we have echoed the same string with double quotes and single quotes. Here is the output.

beginners guide php

When we use double quotes, it displays the string along with the values assigned to variables $a and $b . However, when we use single quotes, it will treat the whole statement as string and will display variables $a and $b. I will touch upon the concept of variables in detail in the next tutorial as well.

Thats it! that is how you start your PHP scripts ! In the upcoming weeks, I will be discussing more about PHP; from the most basic tutorials to the most advanced. I hope to see you around for more PHP tutorials.

In the meanwhile, you can sign up and deploy PHP on the revolutionary managed Cloud Hosting Platform. Choose your cloud provider from some of the best infrastructures around, namely Google Compute Engine, DigitalOcean and Amazon Web Services. It will take you less than 6 minutes to sign up, choose the cloud provider and deploy PHP on your selected cloud provider. It is fast and secure. Plus, you are always covered with a 24/7 support team that never keeps you at bay!

Источник

Оцените статью