Malhar Lathkar

Malhar Lathkar

103 Articles Published

Articles by Malhar Lathkar

Page 4 of 11

PHP HTTP context options

Malhar Lathkar
Malhar Lathkar
Updated on 21-Sep-2020 583 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
Malhar Lathkar
Updated on 21-Sep-2020 503 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

Read More

PHP variable Variables

Malhar Lathkar
Malhar Lathkar
Updated on 19-Sep-2020 2K+ 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
Malhar Lathkar
Updated on 19-Sep-2020 399 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
Malhar Lathkar
Updated on 19-Sep-2020 388 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
Malhar Lathkar
Updated on 19-Sep-2020 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
Malhar Lathkar
Updated on 19-Sep-2020 9K+ 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

PHP NULL

Malhar Lathkar
Malhar Lathkar
Updated on 19-Sep-2020 7K+ Views

Definition and UsageIn PHP, a variable with no value is said to be of null data type. Such a variable has a value defined as NULL. A variable can be explicitly assigned NULL or its value been set to null by using unset() function.Syntax$var=NULL;It is possible to cast variable of other type to null, although casting null to other type has been deprecated from PHP 7.2. In earlier versions, casting was done using (unset)$var syntaxFollowing example shows how to assign NULL to a variableExample Live DemoOutputThis will produce following result −NULLFollowing example performs null variable to other primary variablesExample Live DemoOutputThis will ...

Read More

PHP Iterables

Malhar Lathkar
Malhar Lathkar
Updated on 19-Sep-2020 1K+ Views

Definition and UsageFrom version 7.1 onwards, PHP provides a new pseudo-type called iterable. Any object (such as array) that implements Traversable interface is acceepted by it. This type uses foreach construct or a generator function that yields one value at a a time.SyntaxA function can have iterable as type of its parameter to let the function accept a set of values used in foreach statement. If the parameter doesn't support foreach loop, PHP parser throws TypeErrorExample Live DemoOutputThis will produce following result −PHP Java PythonA PHP function can also return an iterable data type such as array. We use is_iterable() function to ...

Read More

PHP Floating Point Data Type

Malhar Lathkar
Malhar Lathkar
Updated on 19-Sep-2020 889 Views

Definition and UsageIn PHP, float data type represents any number with a provision to contain a fractional part. The fractional part may contain digits after decimal point, or may be represented in scientific notation using either e or E. For example 100 in scientific notation is 10e2.Size of a float depends on the hardware/OS platform, although precision upto 14 digits after decimal point is commonly found.Syntax//Literal assignment of float value to variable $var=5327.496; // standard notation $var1=5.327496e3; // Scientific notation $var2=5.327496E3; //Scientific notation $var3=5_327.496; //sepration symbolFor better readibility, integer literal may use "_" as separation symbol which will be omitted by ...

Read More
Showing 31–40 of 103 articles
« Prev 1 2 3 4 5 6 11 Next »
Advertisements