strip_tags() function is used to retrieve the string from a text by omitting HTML, XML and PHP tags. This function has one mandatory parameter and one optional parameter. The optional parameter is used to accept particular tags.
Sample code:
//Remove all tags from the text
echo strip_tags("<b>PHP</b> is a popular <em>scripting</em> language");
//Remove all tags excluding <b> tag
echo strip_tags("<b>PHP</b> is a popular <em>scripting</em> language","<b>");
Posted Date:- 2021-08-17 11:01:34
mysql_pconnect() ensure a persistent connection to the database, it means that the connection does not close when the PHP script ends.
This function is not supported in PHP 7.0 and above
Posted Date:- 2021-08-17 10:59:31
In PHP, type hinting is used to specify the expected data type (arrays, objects, interface, etc.) for an argument in a function declaration. It was introduced in PHP 5.
Whenever the function is called, PHP checks if the arguments are of a user-preferred type or not. If the argument is not of the specified type, the run time will display an error and the program will not execute.
It is helpful in better code organization and improved error messages.
Posted Date:- 2021-08-17 10:56:33
There is not a way to directly delete a cookie. Just use the setcookie function with the expiration date in the past, to trigger the removal mechanism in your web browser.
Posted Date:- 2021-08-17 10:53:12
In PHP, echo is used to print data on the webpage.
Example: <?php echo ‘Car insurance’; ?>
Posted Date:- 2021-08-17 10:52:30
unlink() function is used in PHP to delete any file.
Sample code:
unlink('filename');
Posted Date:- 2021-08-17 10:50:21
The final keyword in a declaration of the method indicates that the method cannot be overridden by subclasses. A class that is declared as final cannot be subclassed.
This is especially useful when we are creating an immutable class like the String class. Only classes and methods may be declared final, properties cannot be declared as final.
Posted Date:- 2021-08-17 10:47:51
The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error 'maximum execution time exceeded.' It is also possible to specify this in the php.ini file.
Posted Date:- 2021-08-17 10:46:20
If the function require() cannot access the file then it ends with a fatal error. However, the include() function gives a warning, and the PHP script continues to execute.
Posted Date:- 2021-08-17 10:45:43
imagetypes() gives the image format and types supported by the current version of GD-PHP.
Posted Date:- 2021-08-17 10:44:57
The basic steps to create MySQL database using PHP are:
1. Establish a connection to MySQL server from your PHP script.
2. If the connection is successful, write a SQL query to create a database and store it in a string variable.
3. Execute the query.
Posted Date:- 2021-08-17 10:43:42
There are three types of array in PHP:
1. Indexed array: an array with a numeric key.
2. Associative array: an array where each key has its specific value.
3. Multidimensional array: an array containing one or more arrays within itself.
Posted Date:- 2021-08-17 10:39:53
The GD library is required to be able to do image functions. It also helps to execute more image functions.
Posted Date:- 2021-08-17 10:37:55
A cookie is a small piece of information stored in a client browser. It is a technique utilized to identify a user using the information stored in their browser. Utilizing PHP, we can both set and get COOKIE.
Posted Date:- 2021-08-17 10:37:29
A session is a super global variable that preserves data across subsequent pages. Session uniquely defines all users with a session ID. So it supports building a customized web application where user tracking is required.
Posted Date:- 2021-08-17 10:37:00
PDO stands for PHP Data Object. PDO is a set of PHP extensions that provide a core PDO class and database, specific drivers. The PDO extension can access any database which is written for the PDO driver. There are several PDO drivers available which are used for FreeTDS, Microsoft SQL Server, IBM DB2, Sybase, Oracle Call Interface, Firebird/Interbase 6 and PostgreSQL databases, etc.
It gives a lightweight, vendor-neutral, data-access abstraction layer. Hence, no matter what database we use, the function to issue queries and fetch data will be the same. And, it focuses on data access abstraction instead of database abstraction.
Posted Date:- 2021-08-17 10:35:58
The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error ‘maximum execution time exceeded.’ It is also possible to specify this in the php.ini file.
Posted Date:- 2021-08-17 10:30:38
You need to change the value of the max_execution_time directive in the php.ini file for increasing the maximum execution time.
For Example,
if you want to set the max execution time for 130 seconds, then set the value as follows,
max_execution_time = 130
Posted Date:- 2021-08-17 10:29:30
gettype() function is used to check the data type of any variable.
Sample cecho gettype(true).''; //boolean
echo gettype(10).''; //integer
echo gettype('Web Programming').''; //string
echo gettype(null).''; //NULLode:
Posted Date:- 2021-08-17 10:27:51
We use the operator '==' to test is two objects are instanced from the same class and have same attributes and equal values. We can test if two objects are referring to the same instance of the same class by the use of the identity operator '==='.
Posted Date:- 2021-08-17 10:25:49
PHP supports only single inheritance; it means that a class can be extended from only one single class using the keyword 'extended'.
Posted Date:- 2021-08-17 10:25:12
Answer: You have to use PHP command in the command line to execute a PHP script. If the PHP file name is test.php then the following command is used to run the script from the command line.
php test.php
Posted Date:- 2021-08-17 10:24:27
No. PHP is a weakly typed or loosely typed language.
This means PHP does not require to declare data types of the variable when you declare any variable like the other standard programming languages C# or Java. When you store any string value in a variable, then the data type is the string and if you store a numeric value in that same variable then the data type is an Integer.
Sample code:
$var = "Hello"; //String
$var = 10; //Integer
Posted Date:- 2021-08-17 10:22:22
There are several benefits of using PHP. First of all, it is totally free to use. So anyone can use PHP without any cost and host the site at a minimal cost.
It supports multiple databases. The most commonly used database is MySQL which is also free to use. Many PHP frameworks are used now for web development, such as CodeIgniter, CakePHP, Laravel, etc.
Posted Date:- 2021-08-17 10:20:25
You can send an e-mail in PHP with mail() function or SMTP details.
Posted Date:- 2021-08-17 10:18:45
count() function is used for fetching the total number records in a table.
Posted Date:- 2021-08-17 10:17:20
They allow making the result of the expression between the tags directly to the browser response.
Posted Date:- 2021-08-17 10:16:42
The 3 main types of errors in PHP are:
1. Notices: Notices are non-critical errors that can occur during the execution of the script. These are not visible to users. Example: Accessing an undefined variable.
2. Warnings: These are more critical than notices. Warnings don’t interrupt the script execution. By default, these are visible to the user. Example: include() a file that doesn’t exist.
3. Fatal: This is the most critical error type which, when occurs, immediately terminates the execution of the script. Example: Accessing a property of a non-existent object or require() a non-existent file.
Posted Date:- 2021-08-17 10:15:57
The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can't print any HTML element before using this function.
Posted Date:- 2021-08-17 10:13:11
The session_start() function is used to start a new session. Also, it can resume an existing session if it is stopped. In this particular case, the return will be the current session if resumed.
Syntax:
session_start();
The session_destroy() function is used to destroy all of the session variables as given below:
<?php
session_start();
session_destroy();
?>
Posted Date:- 2021-08-17 10:11:19
There are 3 types of Arrays in PHP:
1. Indexed Array – An array with a numeric index is known as the indexed array. Values are stored and accessed in linear fashion.
2, Associative Array – An array with strings as index is known as the associative array. This stores element values in association with key values rather than in a strict linear index order.
3. Multidimensional Array – An array containing one or more arrays is known as multidimensional array. The values are accessed using multiple indices.
Posted Date:- 2021-08-17 10:09:05
The crypt() function is used for this functionality as it provides a large number of hashing algorithms that can be used. These algorithms include sha1, sha256, or md5 which are designed to be very fast and efficient.
Posted Date:- 2021-08-17 10:05:52
PHP print output a string. It is a language construct not a function. So the use of parentheses is not required with the argument list. Unlike echo, it always returns 1.
Posted Date:- 2021-08-17 10:05:03
NULL is a particular type which contains only one value: NULL. If you need any variable to set NULL, just assign it.
Posted Date:- 2021-08-17 10:04:19
Traits are a mechanism that lets you create reusable code in PHP and similar languages where multiple inheritances are not supported. It’s not possible to instantiate it on its own.
A trait is intended to reduce the limitations of single inheritance by enabling a developer to reuse sets of methods freely in many independent classes living in different hierarchies of class.
Posted Date:- 2021-08-17 10:03:26
The cons of PHP are:
1. PHP is not suitable for giant content-based web applications.
2. Since it is open-source, it is not secure. Because ASCII text files are easily available.
3. Change or modification in the core behavior of online applications is not allowed by PHP.
4, If we use more features of the PHP framework and tools, it will cause poor performance of online applications.
5. PHP features a poor quality of handling errors. PHP lacks debugging tools, which are needed to look for warnings and errors. It has only a few debugging tools in comparison to other programming languages.
Posted Date:- 2021-08-17 10:00:17
The final keyword in a method declaration indicates that the method cannot be overridden by subclasses. A class that is declared final cannot be subclassed. This is particularly useful when we are creating an immutable class like the String class.Properties cannot be declared final, only classes and methods may be declared as final.
Posted Date:- 2021-08-17 09:54:37
The PHP syntax relates Perl and C.
Posted Date:- 2021-08-17 09:49:28
A PHP parser is software that converts source code into the code that computer can understand. This means whatever set of instructions we give in the form of PHP code is converted into a machine-readable format by the parser.
Posted Date:- 2021-08-17 09:42:42
PHP scripts have the ability to generate HTML, and it is possible to pass information from HTML to PHP.
PHP is a server-side language whereas HTML is a client-side language. So PHP executes on the server-side and gets its results as strings, objects, arrays, and then we use them to display its values in HTML.
This interaction helps bridge the gaps and use the best of both languages.
Posted Date:- 2021-08-17 09:41:00
The following two rules are needed to be followed while naming a PHP variable:
1. It evaluates to FALSE in a Boolean context.
2. It returns FALSE when tested with IsSet() function.
Posted Date:- 2021-08-17 09:39:18
To display the output directly to the browser, I will use the special tags <?= and ?>.
Posted Date:- 2021-08-17 09:33:44
In static websites, content can't be changed after running the script. You can't change anything on the site. It is predefined.
In dynamic websites, content of script can be changed at the run time. Its content is regenerated every time a user visit or reload. Google, yahoo and every search engine is the example of dynamic website.
Posted Date:- 2021-08-17 09:32:33
PEAR stands for “PHP Extension and Application Repositoryâ€. PEAR is a framework and repository for all of the reusable PHP components.
PEAR provides a higher level of programming for web developers. It contains all kinds of PHP code snippets and libraries. It also provides you with a command-line interface to automatically install packages.
Posted Date:- 2021-08-17 09:31:09
PHP is partially case sensitive. The variable names are case-sensitive but function names are not. If you define the function name in lowercase and call them in uppercase, it will still work. User-defined functions are not case sensitive but the rest of the language is case-sensitive.
Posted Date:- 2021-08-17 09:30:10
To execute a PHP script, use the PHP Command Line Interface (CLI) and specify the file name of the script in the following way:
1.php script.php
Posted Date:- 2021-08-17 09:29:13
The PHP Data Objects (PDO) is a lightweight, and consistent interface used to access databases in PHP.
Posted Date:- 2021-08-17 09:28:25
for, while, do while and foreach.
Posted Date:- 2021-08-17 09:27:37
PEAR is a framework and repository for reusable PHP components. PEAR stands for PHP Extension and Application Repository. It contains all types of PHP code snippets and libraries. It also provides a command line interface to install “packages†automatically.
Posted Date:- 2021-08-17 09:26:57
PHP is a widely-used, open-source server-side scripting language. PHP is an acronym for “PHP: Hypertext Preprocessor.†It allows the developers to develop dynamic web applications. PHP has various frameworks and CMS for developing dynamic and interactive websites.
Posted Date:- 2021-08-17 09:25:33