Found 1046 Articles for PHP

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

AmitDiwan
Updated on 12-Oct-2020 12:42:22

921 Views

You can use the below syntax to access the value of a foreach.The syntax is as follows −foreach ($yourArrayName as &$anyVariableName)Let’s say we have the following array:$values= array(35, 50, 100, 75);We will now multiple each array value with 5 using the following PHP code −Example Live Demo Output175 250 500 375

Get Root Directory Path of a PHP project?

AmitDiwan
Updated on 12-Oct-2020 12:22:46

19K+ Views

In order to get the root directory path, you can use _DIR_ or dirname().The syntax is as follows −echo _DIR_;The second syntax is as follows−echo dirname(__FILE__);Both the above syntaxes will return the same result.Example Live Demo Output/home/KOq8Zd /home/KOq8Zd

How to remove null values with PHP?

AmitDiwan
Updated on 12-Oct-2020 12:18:25

535 Views

To remove null value in PHP, use array_filter(). It filters the array values. Let’s say the following is our array −$studentDetails = array("firstName" => "John",  "lastName"=> null); echo "The original value is=";print_r($studentDetails);Let’s filter with array_filter() −$result = array_filter($studentDetails);Example Live Demo OutputThe original value is=Array ( [firstName] => John [lastName] => ) After removing null part,the result is=Array ( [firstName] => John )

How to convert array to string PHP?

AmitDiwan
Updated on 12-Oct-2020 12:14:57

283 Views

To convert array to string, use the concept of implode () in PHP. Let’s say the following is our array −$sentence = array('My','Name','is','John');To convert the above array to string −,implode(" ",$sentence)Example Live Demo OutputThe string is = My Name is JohnLet us now see another PHP code wherein we will add separator as well −Example Live Demo OutputThe string is = One*Two*Three

PHP compression Stream Wrappers

Malhar Lathkar
Updated on 22-Sep-2020 10:51:29

337 Views

IntroductionIn PHP, zlib://, bzip2:// and zip:// represent wrappers for respective compression streams.compress:zlib://This works similar to gzopen() function, however, it can be used with filesystem functions like fread() and others.compress://bzip2This is similar to bzopen() function. Both stream wrappers operate even on systems not capable of supporting fopencookie.zip://The ZIP extension registers this wrapper. From PHP 7.2.0 onwards, archives encrypted with passwords are supported. It is possible to set password with password context option.Exampleszlib compression can be applied with following PHP codeTo uncompress, we can use following syntaxWe can also use built-in copy() function to build compressed zlib file and uncompress the samecopy('file.txt', ... Read More

PHP ssh2://

Malhar Lathkar
Updated on 22-Sep-2020 10:50:15

199 Views

IntroductionThe libssh2 library provides access to resources on a remote machine using a secure cryptographic transport. These are shell, remote exec, tunneling, file transfer and SCP. PHP has wrappers for these resources. They are ssh2.shell://, ssh2.exec://, ssh2.tunnel://, ssh2.sftp://, and ssh2.scp:// respectivelyNote that these wrappers are not enabled by default. SSH2 extension available from PECL must be installed.Usagessh2.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/filenamessh2.*// context optionssessionPreconnected ssh2 resource to be reusedsftpPreallocated sftp resource to be reusedmethodsKey exchange, hostkey, cipher, compression, and MAC methods to use callbacksusernameUsername to connect aspasswordPassword to use with password authenticationpubkey_fileName of public key file to use for authenticationprivkey_fileName of private key file ... Read More

PHP rar://

Malhar Lathkar
Updated on 22-Sep-2020 10:48:58

216 Views

IntroductionThe RAR (Roshal Archive) is file compression format that supports error recovery and file spanning. PHP supports use of .RAR files as IO stream. The rar:// is a stream wrapper for RAR streams.rar:// wrapper takes the relative or absolute url encoded path to the RAR archive. An optional (*), or (#) and an optional url encoded entry name, as stored in the archive. This wrapper can open both files and directories.If the pound sign and the entry name part are not included, the root of the archive will be displayed. The usage of the wrapper with RecursiveDirectoryIterator requires the number sign to ... Read More

PHP php://

Malhar Lathkar
Updated on 22-Sep-2020 10:47:26

1K+ Views

IntroductionThe php://wrapper enableaccess to various I/O streams. This includes standard input, output and error streams. In-memory, disk backed and filtered streams are lso accessed with php:// protocol.Standard streamsphp://stdin, php://stdout and php://stderr allow direct access to standard input stream device, standard output stream and error stream to a PHP process respectively. Predefined constants STDIN, STDOUT and STDERR respectively represent these streams.php://inputphp://input allows read-only acess to raw data contained in HTTP request body. Note that same data is available in $HTTP_POST_RAW-DATA variable (which is now deprecated). However, php://input is not available for enctype attribute is set to multipart/form-dataphp://outputThis wrapper represents write-only tream, allowing buffer ... Read More

PHP phar://

Malhar Lathkar
Updated on 22-Sep-2020 10:45:40

1K+ Views

IntroductionThe phar:// stream wrapper is available in all PHP versions after 5.3.0. Phar stands for PHP Archive. It is used to distribute PHP application or library and is executed as a normal PHP file. The phar:// wrapper supports opening file with fopen() for read/write, rename, and directory stream operations opendir() as well as create and remove directories.Phar class allows packaging application resources contained inside a directory in a phar archive. To perform read operations, this archive is put in phar:// wrapperBuilding phar archiveTo begin with, ensure that phar.readonly setting in php.ini is set to 0. Then, create a src folder in which ... Read More

PHP http://

Malhar Lathkar
Updated on 22-Sep-2020 10:44:14

200 Views

IntroductionThe http:// and https:// wrappers enable read only access to resources and files through HTTP procol. When handling virtual name-based host,  host: header is also sent along with user_agent (if configured in php.ini)The http header information is stored in $http_response_header variable. These headers have to be processed to know URL of resource where the document comes from with the help of from: header.HTTPS is supported only if openssl extension is enabled in php.ini settings. Both HTTP and HTTPS connections are read only and don't support writing or copying files.UsageRepresentation of file name in different possible ways is as follows −http://localhost http://example.com http://localhost?name='Ram'&age=20 https://example.com http://username:password@abc.comExampleAbove ... Read More

Advertisements