PHP Articles

Page 29 of 81

How to check a file is video type or not in php?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

In PHP, you can check if a file is a video type by examining its file extension. The most common approach is to extract the extension using explode() and end() functions, then compare it against known video formats. Basic Extension Check Here's how to check for a single video format like MP4 − The movie demo.mp4 is of video type. Multiple Video Format Check For a more comprehensive solution that checks multiple video formats − movie.mp4 is a video file video.avi is a ...

Read More

How to access and return specific value of a foreach in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In PHP, you can access and modify array values within a foreach loop by using a reference operator (&). This allows you to directly modify the original array elements during iteration. Syntax The basic syntax for accessing values by reference in foreach is ? foreach ($yourArrayName as &$anyVariableName) { // Modify $anyVariableName to change original array } Example Let's multiply each array value by 5 using foreach with reference ? 175 250 500 375 Key Points When using references in ...

Read More

Get Root Directory Path of a PHP project?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 23K+ Views

In PHP, you can get the root directory path of your project using built-in constants and functions. The most common approaches are using __DIR__ or dirname(__FILE__). Using __DIR__ Constant The __DIR__ constant returns the directory path of the current file − Using dirname(__FILE__) The dirname(__FILE__) function achieves the same result − Comparison Example Here's both methods demonstrated together − Using dirname(__FILE__): /home/KOq8Zd Using __DIR__: /home/KOq8Zd Getting Project Root Directory To get the actual project root (not just ...

Read More

How to remove null values with PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 798 Views

To remove null values in PHP, use array_filter(). This function filters out elements that are considered empty, including null values, from an array ? Syntax array_filter(array $array, callable $callback = null, int $mode = 0) Basic Example Here's how to remove null values from an associative array ? Original array: Array ( [firstName] => John [lastName] => [age] => 25 ) After removing null values: Array ( [firstName] => John ...

Read More

How to convert array to string PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 451 Views

In PHP, you can convert an array to a string using the implode() function. This function joins array elements together with a specified separator string. Syntax implode(separator, array) Parameters separator − Optional string to use as separator between array elements array − The array to convert to string Example 1: Basic Array to String Conversion Here's how to convert a simple array to a string using spaces as separator − The string is = My Name is John Example 2: Using Custom ...

Read More

PHP compression Stream Wrappers

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 536 Views

In PHP, compression stream wrappers provide an efficient way to handle compressed files directly through filesystem functions. The main compression wrappers are compress.zlib://, compress.bzip2://, and zip://. compress.zlib:// Wrapper This wrapper works similar to the gzopen() function but can be used with standard filesystem functions like fread(), file_get_contents(), and file_put_contents(). Creating Compressed Files You can create gzip−compressed files directly using the zlib wrapper − Reading Compressed Files To read and decompress the content, use the same wrapper − Using copy() Function The built−in copy() function ...

Read More

PHP ssh2://

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 425 Views

The ssh2:// wrapper in PHP provides secure access to remote resources using the libssh2 library. It enables shell access, remote execution, tunneling, file transfer, and SCP operations through cryptographic transport. Installation Required: The SSH2 extension must be installed from PECL as it's not enabled by default in PHP. Install using: pecl install ssh2 Available SSH2 Wrappers PHP provides several SSH2 wrappers for different operations − ssh2.shell://user:pass@example.com:22/xterm ssh2.exec://user:pass@example.com:22/usr/local/bin/somecmd ssh2.tunnel://user:pass@example.com:22/192.168.0.1:14 ssh2.sftp://user:pass@example.com:22/path/to/filename ssh2.scp://user:pass@example.com:22/path/to/filename Basic Example Here's how to read a remote file using SSH2 SFTP wrapper − ...

Read More

PHP rar://

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 376 Views

The RAR (Roshal Archive) is a file compression format that supports error recovery and file spanning. PHP supports the use of .RAR files as IO streams through the rar:// stream wrapper. The rar:// wrapper takes the relative or absolute URL encoded path to the RAR archive, with an optional asterisk (*) or hash (#) and an optional URL encoded entry name as stored in the archive. This wrapper can open both files and directories. Installation Required: This wrapper is not enabled by default. You must install the RAR extension from PECL (PHP Extension Community Library) using: pecl ...

Read More

PHP http://

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 443 Views

The http:// and https:// wrappers in PHP enable read-only access to resources and files through the HTTP protocol. When handling virtual name-based hosts, the host: header is sent along with user_agent (if configured in php.ini). The HTTP header information is stored in the $http_response_header variable. These headers help identify the URL of the resource where the document originates from using the from: header. HTTPS is supported only if the openssl extension is enabled in php.ini settings. Syntax The HTTP/HTTPS wrapper can be used in different formats − http://localhost http://example.com http://localhost?name='Ram'&age=20 https://example.com http://username:password@abc.com Key ...

Read More

PHP glob://

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 517 Views

The glob:// stream wrapper is available in all PHP versions after 5.3.0. It finds pathnames that match given pattern. Similar purpose is fulfilled by PHP's filesystem function glob() which follows libc glob() rules. Parameters Special Characters * − Matches zero or more characters. ? − Matches exactly one character (any character). [...] − Matches one character from a group of characters. If the first character is !, matches any character not in the group. \ − Escapes the following character, except when the GLOB_NOESCAPE flag is used. Valid Flags GLOB_MARK − Adds ...

Read More
Showing 281–290 of 802 articles
« Prev 1 27 28 29 30 31 81 Next »
Advertisements