If you require redirecting a user from one web page to another by using PHP, you may use the header function.
PHP provides built-in functions for uppercase, lowercase and camel case conversion. This tutorial explains how to use these with examples.
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.
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:
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
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
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
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
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
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
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
Search string in PHP In the last chapter, I explained how you can use the strpos function of PHP to search strings. I used hard-coded values along with a demo where a user entered value is taken to search string by using an HTML form. As a user presses the submit / search button, it will … Read more
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