Found 1046 Articles for PHP

PHP Phar context options

Malhar Lathkar
Updated on 21-Sep-2020 09:28:45

141 Views

IntroductionPhar stands for PHP Archive. All the resources of a certain PHP application or library are packages in a single .phar file for the purpose of istribution. A phar file can be used as IO stream with phar:// wrapper. Context options for phar:// wrapper are listed as follows −compressPHP has following predefined constants for defining compression formatsConstantValueDescriptionPhar::NONE0x00000000no compressionPhar::COMPRESSED0x0000F000bitmask with file flags to determine if any compression is presenPhar::GZ0x00001000zlib (gzip) compressionPhar::BZ20x00002000bzip2 compressionmetadataAny PHP variable containing information to store that describes the phar archive is used as argument for Phar::setMetadata() methodExampleThis example Phar context option set for creating Phar fileRead More

PHP Context Parameters

Malhar Lathkar
Updated on 21-Sep-2020 09:23:20

406 Views

IntroductionContext parameters allow customization of access to filesystem and other stream wrappers. To configure a stream, PHP has stream_context_set_params() function.Syntaxstream_context_set_params ( resource $stream_or_context , array $params ) : bool$stream_or_context can be any of PHP's supported streams/wrappers/contexts$params is an array with following properties. should be an associative array of the structure − $params['paramname'] = "paramvalue";context parametersnotification − A user-defined callback to be called whenever a stream triggers a notification. Only for http:// and ftp:// stream wrappers.The notification callback function has following syntaxsyntaxstream_notification_callback ( int $notification_code , int $severity , string $message , int $message_code , int $bytes_transferred , int $bytes_max ) ... Read More

PHP MongoDB context options

Malhar Lathkar
Updated on 21-Sep-2020 09:21:52

104 Views

IntroductionPHP can interact with MongoDB database through database extensions. For older versions of PHP, mongo driver can be installed from PECL. This has now been replaced by mongodb driver. Both drivers can be installed using precompiled binaries for Linux/Windows/MacOS operating systems. Alternately, manual installation can be done from source tarball available on github. In either case, mongo or mongodb extension should be enabled in php.ini settings.The PHP MongoDB extension provides Stream Context Support using the mongodb context. Relevent context options are as followsOptionslog_cmd_insert ( array $server , array $document , array $writeOptions , array $protocolOptions )This is a callable function, used ... Read More

PHP HTTP context options

Malhar Lathkar
Updated on 21-Sep-2020 09:19:04

349 Views

IntroductionGiven below is the list of context options for http:// and https:// transportsmethodHTTP method supported by the remote server. Defaults to GET.headerAdditional headers to be sent during request.user_agentValue to send with User-Agent: header. By default the user_agent php.ini setting is used.contentAdditional data to be sent after the headers. Typically used with POST or PUT requests.proxyURI specifying address of proxy server.request_fulluri booleanWhen set to TRUE, the entire URI will be used when constructing the request. Defaults to FALSE.follow_locationFollow Location header redirects. Set to 0 to disable.Defaults to 1.max_redirectsThe max number of redirects to follow.protocol_versionHTTP protocol version. Defaults to 1.0.timeoutRead timeout in seconds, ... Read More

PHP FTP context options

Malhar Lathkar
Updated on 21-Sep-2020 09:13:52

299 Views

IntroductionContext options for http:// and https:// transports are listed below −overwriteAllow overwriting of already existing files on remote server while uploading only.resume_posFile offset at which to begin transfer. Applies for downloading only.Defaults to 0 (Beginning of File).proxyProxy FTP request via http proxy server. Applies to file read operations only. Ex −tcp://squid.example.com:8000.This example shows how to allow fopen() to overwrite a file on an FTP site.Example

PHP variable Variables

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

1K+ Views

IntroductionIn PHP, it is possible to set variable name dynamically. Such a variable uses value of an existing variable as name. A variable variable is defined with two $ signs as prefixExample Live DemoOutputThis script produces following outputxyz abcd abcd abcdNote that value of $$var1 is same as $xyz, xyz being value of $var1.Numeric value of normal variable cannot be used as variable variableExample Live DemoOutputWhen this script is executed, following result is displayedPHP Parse error: syntax error, unexpected '100' (T_LNUMBER), expecting variable (T_VARIABLE) or '{' or '$' line 6It is also possible to define a variable variable in terms of an ... Read More

PHP Variables from External Sources

Malhar Lathkar
Updated on 19-Sep-2020 15:05:20

224 Views

IntroductionPHP's variable namespace is populated by external sources such as HTML form elements, cookies and screen coordinates of image submit buttonHTML form elementsWhen a web page submits data in its HTML form to a PHP script, it is automatically made available to the script in the form of $_POST, $_GET and $_REQUEST variables. Following is a typical HTML form             Data entered by user is populated as $_POST associative array in PHP scriptPlace HTML page in document root along with testscript.php. Open it in browser and enter dataName : xyz Age : 20Using method='GET' in ... Read More

PHP Variable Basics

Malhar Lathkar
Updated on 19-Sep-2020 15:03:34

330 Views

IntroductionName of a variable in PHP starts with a $ sign. It is followed by either a letter (A-Z either upper or lowe case) or underscore, and then there may be any number of letters, digits or underscores. Name of variable in PHP is case sensitive.Syntax//valid variables $var=10; $VAR="Hello"; //different from $var $marks_1=67; $_val=0; //invalid variables var=10; //not starting with $ $4sqr=16; //not starting with letter/_ $my name="Hello"; //white space not allowed in variable name $my$name="Hello"; //$ character can not be used after first positionA variable is also assigned a value by reference to another variable. To assign value by ... Read More

PHP String Data Type

Malhar Lathkar
Updated on 19-Sep-2020 14:58:10

2K+ Views

Definition and UsageIn PHP, a string data type is a non-numeric sequence of charaters.Any character in the ASCII set can be a part of a string. PHP doesn't support UNICODE.In PHP, literal representation of string can be done with single quotes, double quotes, with heredoc syntax and nowdoc syntax.Syntax//Literal assignment of string value to variable $var='Hello World'; //Single quotes $var3="Hello World"; //Double quotesTo embed single quote character inside single quoted string prefix it with '\'. Similarly to embed backslash in single quoted string prefix it with additional backslash. Other escape sequence characters such as etc. do not carry any ... Read More

PHP Resources

Malhar Lathkar
Updated on 19-Sep-2020 14:53:19

7K+ Views

Definition and UsageIn PHP, Resource  is a special data type that refers to any external resource. A resource variable acts as a reference to external source of data such as stream, file, database etc. PHP uses relevent functions to create these resources. For example, fopen() function opens a disk file and its reference is stored in a resource variable.PHP's Zend engine uses reference conting system. As a result, a resource with zero reference count is destroyed automatically by garbage collector. Hence, memory used by resource data type need not be freed manually.Various types of resources can be handled in a ... Read More

Advertisements