Search

Welcome to our website

Codinger is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using Codinger.in, you agree to have read and accepted our terms of use, cookie and privacy policy.

Latest Articles

The latest articles from our blog, you can browse more

Contact Details

Address:

Dabri, India 335503

Mobile:

+918596086960

Get in touch with us by filling contact form below

Frequently asked questions

Find clear answers to common questions and past inquiries, Clear answers to common curiosities.

What is PHP




  • Programming language that is used to build web applications and websites.

  • PHP stands for Hypertext Preprocessor.

  • PHP is a server-side scripting language.

  • PHP is faster than other scripting languages, such as ASP and JSP.



What is PHP?

PHP is a programming language you can use to create web applications. It's free, powerful, relatively easy to set up and learn, and it has extensions and frameworks available to do almost anything you could imagine. You can get started quickly, and you won't outgrow it later when you get really good at it. In my humble opinion, PHP is a great language that will be well worth it the time and effort you put into learning it.

Frankly, it's justplain fun too.

Let's get started. The most basic concept you need to grasp is that a web page is just a bunch of text, organized in a certain way, which is displayed by a browser. Only a few companies make browsers, but millions of people make web pages and so can you.

Most computer programs need some way to know if a file is intended for them or not. In the PC world, this is accomplished by file extensions. (Bear with me, this next bit is relevant). For example, a file named "my book.docx" is associated with Microsoft Word because its extension (the text following the dot) is "docx". Similarly, a PowerPoint file might end with .ppt or .pptx. Other programs also have their own unique extensions.

A web page typically, but not exclusively, has an extension such as .htm or .html to indicate that it is an HTML file. An HTML file can be on your own computer, or on a different computer somewhere out on the Internet. The browser doesn't care. Here's a simple example of an html file out on the Internet:



This was about the simplest web page I could find... just two links to other pages. Notice that the last four characters are .htm, which indicates that it is an HTML file intended for display in a browser. If that file were on your local computer, for instance in your "My Documents" folder, all you would have to do to see it in a browser would be to double-click on it.

Your browser would know how to do the rest and you would see something like this:



This particular file is not on your local computer, however. It is on a server out on the Internet. So how does the file get into your browser when you click on it? At the risk of

oversimplifying it, you don't have to worry about that part so much. The other computer, known as the "web server", has the file and it knows how to get it to you.

In the case of an HTML file such as this one, the server sends the file as is without doing anything to it. In other words, the file that the browser gets is exactly the same as the file on the file system, regardless of whether it was originally on your computer or on the server.

We would call this a static web page.



Introducing PHP

Now let's add PHP to the picture. PHP has several meanings depending on the context in which it is used, so I'm going to try to explain them all. There is a "PHP server", which is a web server that is running PHP software on it. Let's contrast a PHP server with a "plain" server, one that is not running PHP. A "plain" web server just takes a request from a browser, locates the appropriate file, and sends it to the browser as is, with no manipulation. In other words, it only serves static web pages.

Once you add PHP to a web server, you get additional functionality-without taking any existing functionality away. The server can still continue to send static HTML files to the browser, but it can also manipulate the files prior to sending them to the browser.

A file that has been manipulated prior to being sent to the browser is referred to as a dynamic web page.




A static web page never changes, unless a person specifically edits the page.
A dynamic web page can be different every time it is
viewed by a browser, because the server edits the page prior to sending it to the browser, according to what instructions the programmer has coded into that specific page.


Example

Here's an example. Let's say you have a web page on which you wanted the current date to appear. With a static web page, you would have to go in and edit the page every single day to update the date. That would get tiresome pretty quick!

The HTML code would look something like this:




<html>
<body>
Hello world! Today's date is the 7th of October 2012
</body>
</html>


With PHP you can let the server make the changes for you. In other words, PHP can dynamically add the correct date to the page every time the page is served if you insert a little bit of PHP code like this:




<html>
<body>
Hello world! Today's date is the <?php echo date('jS \o\f F Y'); ?>
</body>
</html>


And the cool thing is that it works every day, without any further manipulation. Are you starting to see the joy?

How does a server know whether a page should be dynamic or static? An ordinary server only knows static pages. A PHP server knows that a file should be manipulated (it is dynamic) if it is "PHP file" and that it should not be manipulated (it is static) if it is an HTML file.

What's the difference between an HTML file and a PHP file? A PHP file is basically just an HTML file with some code inside it that tells the server to swap out the code part and insert text (or HTML) in its place. A PHP file is "just" an HTML file that has been saved with a different extension - ".php". Here's an example:

http://php.net/manual/en/tutorial.firstpage.php



A PHP file is just an HTML file saved using a .php extension instead of an.html or .htm extension, which tells the server to look in the page for code.

What is the "extra code" that goes inside a PHP file instructing the page to be manipulated? That's PHP the language, which tells the server how and where the page should be manipulated prior to sending it to the browser. In other words, PHP is a programming language that is used to create dynamic web pages.



PHP is a language that can be used to create dynamic web pages. In fact, that is the point of PHP.



How does the server know which parts of the page should be static and which parts should be dynamic? In general, the server leaves the page alone. However, if it sees the text <?php then all the text that follows will be treated like code, until it comes to a ?> which signals the server to go back to sending the page as is.



Text on a PHP page is normally static. The PHP server will dynamically convert the text that appears in between <?php and ?> tags into static text, after evaluating what the code means.



A little history

PHP was originally created by Rasmus Lerdorf in 1995. The main implementation of PHP is now produced by The PHP Group and serves as the formal reference to the PHP language. PHP is free software released under the PHP License, which is incompatible with the GNU General Public License (GPL) due to restrictions on the usage of the term PHP.

While PHP originally stood for Personal Home Page, it is now said to stand for PHP: Hypertext Preprocessor, a recursive acronym.

Radio buttons in PHP code are handled by first defining them within an HTML form and then processing their selected value using PHP when the form is submitted.



1. HTML Form with Radio Buttons:



Create an HTML form containing the radio buttons. It is crucial that all radio buttons within a group (where only one can be selected) share the same name attribute but have distinct value attributes.



1. HTML Form with Radio Buttons:



Create an HTML form containing the radio buttons. It is crucial that all radio buttons within a group (where only one can be selected) share the same name attribute but have distinct value attributes.



2. PHP Processing (process_radio.php):



In the PHP file specified in the form's action attribute (e.g., process_radio.php), you can retrieve the selected radio button's value using the $_POST superglobal array.




<?php
if (isset($_POST['submit_button'])) {
    if (isset($_POST['fav_color'])) {
        $selectedColor = $_POST['fav_color'];
        echo "You selected: " . htmlspecialchars($selectedColor);
    } else {
        echo "No color was selected.";
    }
}
?>


 

Indexed arrays can be created in PHP using two primary methods: Using the array() constructor.




$fruits = array("apple", "banana", "orange");



  • Using the short array syntax (square brackets []




$colors = ["Red", "Green", "Blue"];
PHP, a widely used server-side scripting language, offers a range of features that make it a popular choice for web development. Key features include:
  • PHP is Simple and Easy to Learn: The syntax of PHP compared to that of C, Java, and Perl, which makes it rather simple for developers to comprehend, particularly for those who are already familiar with other programming languages. Web apps can be developed quickly because of its generous pre-defined functions.
  • Open Source and Free: PHP is open-source, allowing free use, modification, and distribution of its source code.
  • Platform Independence: PHP code is designed to run across various operating systems, including Windows, Linux, Unix, and macOS, ensuring broad compatibility.
  • Ease of Use and Learning: PHP boasts a relatively simple and approachable syntax, making it easier to learn, especially for those familiar with C-like languages.
  • Embedded HTML Support: PHP code can be seamlessly embedded within HTML, facilitating the creation of dynamic web content.
  • Extensive Database Integration: PHP provides robust support for connecting to and interacting with various databases, such as MySQL, PostgreSQL, Oracle, and SQLite.
  • Rich Built-in Functions and Libraries: PHP offers a comprehensive set of built-in functions and libraries, simplifying common web development tasks like image processing, encryption, and handling sessions and cookies.
  • Server-Side Scripting: As a server-side language, PHP processes data on the server before sending it to the client's browser, enabling dynamic content generation and secure data handling.
  • Scalability and Performance: Modern PHP versions, particularly PHP 7 and newer, have introduced significant improvements in performance and memory usage, enhancing scalability for various project sizes.
  • Security Features: PHP includes built-in features for security, such as data encryption and secure session handling, and also benefits from a large community that addresses security concerns.
  • Strong Community and Documentation: PHP has a vast and active community, providing extensive resources, documentation, and support for developers.
  • Frameworks and CMS Support: PHP serves as the foundation for numerous powerful frameworks (e.g., Laravel, Symfony) and Content Management Systems (e.g., WordPress, Drupal), streamlining web development and content management.