In PHP, using the $_SERVER variable is the easiest way to get the full URL.
Using $_SERVER Variable
$_SERVER is an array containing information such as headers, paths, and script locations.
The following example should cover whatever you are trying...
In PHP, there are 2 ways to check if a string contains a specific word.
Using strpos Function
The strpos(string $haystack, string $needle, int $offset = 0): int|false function finds the numeric position of the first occurrence of needle in the hayst...
In PHP, there are 3 ways to delete an element from an array.
Using unset Function
The unset(mixed $var, mixed ...$vars): void function destroys the specified variables. For example,
$arr = ["a", "b", "d"];
unset($arr[1]);
print_r($arr);
Arr...
Reverse the order of an array.Using array_reverse Function
The array_reverse() return an array with elements in reverse order.
$arr = array("PHP", 8.1, 4);
$reversed = array_reverse($arr);
print_r($reversed);
$preserved = array_reverse($arr, true);...
Reverse a Unicode String in PHP.Using strrev Function
The strrev() reverse a string.
// !olleH
echo strrev("Hello!");
// does not support utf-8 encoding
strrev("Hello,世界");
!olleH
Using For Loop
FOR LOOP will start with the value of the length o...
Formatting PHP Strings with printf and sprintf.
Using sprintf Function
The sprintf() return a formatted string.
sprintf(string $format, mixed ...$values): string
// iPhone 14 Pro
echo sprintf("%s %d Pro\n", "iPhone", 14);
// iPhone 14 Pro
prin...
Printing all properties of an object.
Using print_r Function
The print_r() prints human-readable information about a variable. If given a string, int or float, the value itself will be printed. If given an array, values will be presented in a format...
How Hashing Function Works and its Syntax.
MD5 Function
The md5() calculates the md5 hash of a string. Returns the hash as a 32-character hexadecimal number.
$str = "Google";
// 8b36e9207c24c76e6719268e49201d94
echo md5($str);
// bool(true)
md...
Reduce Bandwidth Usage by Supporting If-Modified-Since in PHP.
If-Modified-Since
The If-Modified-Since request HTTP header makes the request conditional: the server sends back the requested resource, with a 200 status, only if it has been last modif...