All Go Rust Python PHP JavaScript
Chrome Dev Summit to secure your spot in workshops, office hours and learning lounges!

How to Get the Full URL in PHP

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...
url
Sambhav Khandelwal

How to check if a string contains a specific word in PHP

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...
ada

How to Delete an Element from an Array in PHP

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...
Sambhav Khandelwal

How to reverse an array in PHP

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);...
aweis

How to reverse a string in PHP

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...
Tomoki

How to format a string in PHP

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...
Patcher56

How to print an object in PHP

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...
Sambhav Khandelwal

How to use of hash functions in PHP

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...
Tomoki

How to handle If-modified-since header in PHP

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...
Patcher56