PHP String

String means set of characters or letters or combination in single or double quotes. Like ‘PHP Language’. If you placed the number in the single quote or double quotes it’s also a string. Like ‘12345’. Similarly, special characters symbol whatever if you write it in the single or double quote it’s become a string. In … Read more

String functions in PHP- uses and examples

Now list some String functions in PHP to handle and manipulate string in PHP. All functions explained are inbuilt PHP functions also known as predefined string functions in PHP. These functions are defined during creation of PHP. sterlen() Length of String sterlen() function is used to get the entire length of the string. If there … Read more

PHP Form Handling with Examples

PHP Form method is used to sending data from browser to server.

Two types of methods are there GET and POST.

$_GET and $_POST are used to receive value from the form method.

$_GET and $_POST are the global variables so declare it with uppercase otherwise this will not work.

Syntax of GET Method in PHP:

Output:
Bill

Syntax of POST Method in PHP:

Output:
Bill

Note: by default form method is get.

If any user does not declare method attribute in the form tag then value send by getting method automatically.

If any users declare form method attribute value post and receive value in the server using $_GET variable then it does not work same as vice versa.

Get and Post method both are same and used for the same purpose but there has some difference.

Html/Text Response from PHP

Sending any kind of data from the form all go as a string type.

Program: PHP Program to submit user details in PHP form and show in PHP HTML table format.

Output

User Form in php
User Form
User Form in PHP
User Response

Send JSON Response from PHP Form


JSON is another way to use for exchange data format between web client and server.

Enabling HTML forms to submit JSON directly simplifies implementation as it enables backend services to operate by accepting a single input format that is what’s more able to encode richer structure than other form encodings (where the structure has traditional had to be emulated).

Form’s type attribute value set application/ json to transmit JSON data from the form.

Example: Form submit in php to send user details and get PHP JSON response.

Output

PHP Form to enter user details
PHP JSON OUTPUT

Explanation:
By default input type is text.

Value send from the form by method and json_encode is a function which exchanges PHP server data into JSON format.

Example: How to Upload an Image in PHP

Output:

File Upload Example in PHP
Uploaded file detail in PHP

Explanation:
Upload any kind of file through form need set enctype attribute value with multipart/form-data. It means multi-type file can upload from Form.


Next always use post method in form because get method only sends 1kb data.


Next file value receives always in the server via $_FILES[] global array whatever form method in form, Which has 5 parameters name size type tmp_name and error.


Name index return name value of the uploaded file.
Size index returns size value of the uploaded file in bytes.


Type index return uploaded file type value like image/jpg for jpg extension file, application/pdf for pdf file, application/docx for document file, plain/text for text file etc.

Tmp_name index returns the uploaded file location. In server, there has a tmp folder initially where all the uploaded files are stored temporarily.


Error index return by default 0 otherwise if the size or any other index value return any error then error index return 1 or 2

Want Upload pdf file then only change the condition of above example

Example: How to Download a File in PHP


Explanation:
Provide file name to download,set its content type.

on calling url it will get downloaded.

PHP File Upload Example

PHP File Upload is a very important topic in PHP. Build any kind of websites or web application there has must be files. So want know that how can upload files or retrieve those files and download it (if required). You should have basic knowledge of Form Handling in PHP for working uploading a file. … Read more

StringTokenizer in java- Constructor, method with example

1 What is StringTokenizer? A StringTokenizer is a class in Java. It is used to divide strings in form of token based on some delimiters. It is defined in java.util.stringtokenizer 2 StringTokenizer Constructors Sr No Constructor and Description 1 StringTokenizer(String str) Construct a string tokenizer for given string 2 StringTokenizer(String str, String delim) Construct a … Read more

Primitive Data Types in Java

Primitive data types are primary and basic data types in java. In Java there are 8 primitive data types. List of primitive datatypes in java is as follows byte short int long float double char boolean Details of all data types are below. 1 Java Integer Data Type There are four integer data types (byte, … Read more