Programming Articles - Page 1707 of 3366

Total Distance to Visit City Blocks in Python

Arnab Chakraborty
Updated on 22-Sep-2020 10:58:41

243 Views

Suppose we have a matrix of unique strings representing the city blocks, and another list of strings containing blocks to visit. If we are at block matrix[0][0], then find the total Manhattan distance required to visit every block in order.So, if the input is likeQBCDEZGGiBlock = [H, B, C]Then the output will be 6 as "h" is 2 blocks bottom(south) and 1 block right(east), "b" is 2 blocks up(north), "c" is 1 block right(east).To solve this, we will follow these steps −coords := a map with key 'start' and value (0, 0)for each row in mat, dofor each col in ... Read More

PHP compression Stream Wrappers

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

495 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

365 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

317 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

2K+ 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

382 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

PHP glob://

Malhar Lathkar
Updated on 22-Sep-2020 10:42:23

445 Views

IntroductionThe 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.ParametersSpecial 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 flagsGLOB_MARK − Adds a slash (a backslash on Windows) to each directory returnedGLOB_NOSORT − Return files as they appear ... Read More

PHP ftp://

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

405 Views

IntroductionBoth ftp:// and  ftps:// wrappers allow read access to URLs with ftp (and ftps) protocol. New file can also be created using these wrappers. If passive mode ftp support is not possible in the server, connection will fail.Simultaneous read-write operations are not permitted with streams using ftp protocol. If it is required to overwrite existing file, it may be done by specifying overwrite option in context options.The php.ini file has from setting which specifies email ID to be used for unauthenticated FTP connection.If it is set, it is used as anonymous FTP password. It is also possible to have ftp access ... Read More

PHP file://

Malhar Lathkar
Updated on 22-Sep-2020 10:39:17

349 Views

IntroductionVarious URL-style protocols can be used with filesystem functions with the help of corresponding built-in wrappers avalable in PHP. The stream_wrapper_register() function is also there to define custom wrapper.Default wrapper in PHP is file:// and it represents local filesystem. If no other protocol is explicitly used, PHP parser treats it as filesystem wrapper. The filename argument to be given to filesystem functions fopen(),  file_get_contents() etc uses file:// protocol by default.When file name doesn't begin with forward or backward slash, or drive letter in Windows, its path is taken as relative to current directory. However, in fopen() and file_get_contents() functions, file name ... Read More

Advertisements