How to redirect in PHP

If you require redirecting a user from one web page to another by using PHP, you may use the header function.

Categories PHP

How to generate random numbers in PHP?

The PHP rand function generates a random number (integer) from zero to maximum number returned by getrandmax() function. The maximum number in windows platform can be (for example) 32768.

Categories PHP

How to get Array length in PHP?

To get the total number of elements in an array, you may use the PHP count or sizeof functions. For example, this is how you may get the array length by count function:

Categories PHP

PHP Get: Explained with 3 examples

PHP GET jquery

The $_GET in PHP The $_GET is the way to get the values of variables that are passed to the current PHP page via URL parameters. The PHP GET is an associative array, so variable becomes keys. To understand that, consider an HTML form submits information by using the method = get: <form method=”get” action … Read more

Categories PHP

PHP Trim Function for Removing Spaces: 5 Examples

PHP trim arrays

Purpose of trim function in PHP The PHP trim function is used to remove spaces or other characters like a tab, new line, a vertical tab, etc. in a given string. Sometimes, it is required to ensure that the text entered by the users does not contain leading or trailing whitespaces before storing in the … Read more

Categories PHP

8 Examples of PHP str_replace Function to Replace Strings

PHP str_replace case sensitive

The str_replace function The str_replace function of PHP is used to replace a string with the replacement string. PHP str_replace function is case-sensitive. If you want to perform case-insensitive replacements then use the str_ireplace function (see the last example in this tutorial). First, have a look at the str_replace syntax and examples below. Syntax of … Read more

Categories PHP

How to use PHP strlen to Get the String Length with 5 Examples

PHP string length

The strlen function of PHP The strlen function is used to get the length of a string in PHP programs. The function returns bytes unlike the general conception of returning the number of characters in the given string. This is how you may use the strlen function to get string length: int strlen ($string_to_get_length ) … Read more

Categories PHP

The while loop in PHP

PHP while

What is while loop? The PHP while loop is used to execute a given block of code until the given expression in the while is false. This is the simplest type of loop in PHP that works just like C language. The condition or value of the expression is checked at the beginning of the … Read more

Categories PHP

PHP POST: An Associative Array

Visual representation of PHP POST

Learn how to utilize PHP’s POST method with associative arrays through this comprehensive tutorial. Explore HTML form integration and jQuery AJAX for data handling.

PHP include VS require: explained with different examples

PHP include inner

The purpose of include and require statements in PHP The include and require PHP statements are used to include the specified files in the calling file/program. For example: include(“user_auth.php”);   require(“scripts/db_connect.php”); The code of the specified file will be copied to the calling program before execution by using the include or require statements. This feature … Read more

Categories PHP

PHP for Loop: Explained with 6 examples

PHP for

The for loop in PHP PHP supports different types of loops to iterate through a given block of code. These include: for loop, while and do while, and the foreach loop. The for loop is the most complex loop that behaves like in the C language. Structure of for loop Following is the general structure … Read more

Categories PHP

Search strings by PHP strpos / stripos functions | 4 demos

PHP strpos search

The strpos function of PHP The PHP strpos is a string function which is used to search a substring in a given string. It returns the numeric value of the first occurrence of specified search string. Syntax to use strpos This is how you can use the strpos function in PHP: $position = strpos($given_string, $search_string); … Read more

Categories PHP