21⟩ Explain me what is the use of 'print' in php?
This is not actually a real function, It is a language construct. So you can use with out parentheses with its argument list.
Example
print('PHP Interview questions');
print 'Job Interview ';
“Junior PHP Developer related Frequently Asked Questions in various Junior PHP Developer job interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting”
This is not actually a real function, It is a language construct. So you can use with out parentheses with its argument list.
Example
print('PHP Interview questions');
print 'Job Interview ';
The trim() function removes whitespaces or other predefined characters from both sides of a string.
We can include a file using "include() " or "require()" function with file path as its parameter.
Syntax :
array explode ( string $delimiter , string $string [, int $limit ] );
This function breaks a string into an array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.
"method" attribute determines how to send the form-data into the server. There are two methods, get and post. The default method is get. This sends the form information by appending it on the URL. Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
Here are three basic types of runtime errors in PHP:
☛ 1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behavior.
☛ 2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
☛ 3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take place.
PHP syntax resembles Perl and C
If we would like to pass values througn a form or an URL then we need to encode and to decode them using htmlspecialchars() and urlencode().
The result set can be handled using mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_object or mysql_fetch_row.
A static variable is defined within a function only the first time and its value can be modified during function calls as follows:
<!--?php
function testFunction()
{
static $testVariable = 1;
echo $testVariable;
$testVariable++;
}
testFunction(); //1
testFunction(); //2
testFunction(); //3
?-->
1- Combining two variables as follows:
$variable1 = ‘Hello ‘;
$variable2 = ‘World’;
$variable3 = $variable1.$variable2;
Or
2- $variable3 = “$variable1$variable2”;
$variable3 will contain “Hello World”. The first code is faster than the second code especially for large large sets of data.
The session_unregister() function unregister a global variable from the current session and the session_unset() function free all session variables.
The name of the output type have to be specified in parentheses before the variable which is to be cast as follows:
* (int), (integer) – cast to integer
* (bool), (boolean) – cast to boolean
* (float), (double), (real) – cast to float
* (string) – cast to string
* (array) – cast to array
* (object) – cast to object
addslashes function enables us to escape data before storage into the database.
Two methods are possible:
<!--?php echo "Method 1"; print "Method 2"; ?-->
Just use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows:
php script.php
There is a good page in the php manual on the subject, in short mysql_pconnect() makes a persistent connection to the database which means a SQL link that do not close when the execution of your script ends. mysql_connect() provides only for the database new connection while using mysql_pconnect, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection... the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use.
if ($_FILES["file"]["error"] == 0)
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.
Create session : session_start();
Set value into session : $_SESSION['USER_ID']=1;
Remove data from a session : unset($_SESSION['USER_ID'];