How To Read the Entire File into a Single String?
[
]
If you have a file, and you want to read the entire file into a single
string, you can use the file_get_contents() function. It opens the
specified file, reads all characters in the file, and returns them in a
single string. Here is a PHP script example on how to
file_get_contents():
<?php
$file = file_get_contents("/windows/system32/drivers/etc/services");
print("Size of the file: ".strlen($file)."\n");
?>
This script will print:
Size of the file: 7116
Choose your rating:
Post Ans. View More Ans.
What s the difference between include and require?
[
]
It’s how they handle failures. If the file is not found by require(),
it will cause a fatal error and halt the execution of the script. If
the file is not found by include(), a warning will be issued, but
execution will continue.
Choose your rating:
Post Ans. View More Ans.
Explain the ternary conditional operator in PHP?
[
]
Expression preceding the ? is evaluated, if it’s true, then the
expression preceding the : is executed, otherwise, the expression
following : is executed.
Choose your rating:
Post Ans. View More Ans.
How To Turn On the Session Support?
[
]
The session support can be turned on automatically at the site level, or
manually in each PHP page script:
- Turning on session support automatically at the site level: Set session.auto_start = 1 in php.ini.
- Turning on session support manually in each page script: Call session_start() funtion.
Choose your rating:
Post Ans. View More Ans.
How can I embed a java programme in php file and what changes have to be done in php.ini file?
[
]
There are two possible ways to bridge PHP and Java: you can either
integrate PHP into a Java Servlet environment, which is the more
stable and efficient solution, or integrate Java support into PHP. The
former is provided by a SAPI module that interfaces with the
Servlet server, the latter by this Java extension.
The Java extension provides a simple and effective means for creating
and invoking methods on Java objects from PHP. The JVM is created
using JNI, and everything runs in-process.
Example Code:
getProperty('java.version') . ''; echo 'Java vendor=' .
$system->getProperty('java.vendor') . ''; echo 'OS=' .
$system->getProperty('os.name') . ' ' .
$system->getProperty('os.version') . ' on ' .
$system->getProperty('os.arch') . ' '; //
java.util.Date example $formatter = new
Java('java.text.SimpleDateFormat', "EEEE, MMMM dd, yyyy 'at' h:mm:ss a
zzzz"); echo
$formatter->format(new Java('java.util.Date')); ?>
The behaviour of these functions is affected by settings in php.ini.
Table 1. Java configuration options
Name
Default
Changeable
java.class.path
NULL
PHP_INI_ALL
Name Default Changeable
java.home
NULL
PHP_INI_ALL
java.library.path
NULL
PHP_INI_ALL
java.library
JAVALIB
PHP_INI_ALL
Choose your rating:
Post Ans. View More Ans.
Explain about Type Juggling in php?
[
]
PHP does not require (or support) explicit type definition in variable
declaration; a variable's type is determined by the context in
which that variable is used. That is to say, if you assign a string
value to variable $var, $var becomes a string. If you then assign an
integer value to $var, it becomes an integer.
An example of PHP's automatic type conversion is the addition operator
'+'. If any of the operands is a float, then all operands are
evaluated as floats, and the result will be a float. Otherwise, the
operands will be interpreted as integers, and the result will also be
an integer. Note that this does NOT change the types of the operands
themselves; the only change is in how the operands are evaluated.
$foo += 2; // $foo is now an integer (2)
$foo = $foo + 1.3; // $foo is now a float (3.3)
$foo = 5 + "10 Little Piggies"; // $foo is integer (15)
$foo = 5 + "10 Small Pigs"; // $foo is integer (15)
If the last two examples above seem odd, see String conversion to numbers.
If you wish to change the type of a variable, see settype().
If you would like to test any of the examples in this section, you can use the var_dump() function.
Note: The behavior of an automatic conversion to array is currently undefined.
Since PHP (for historical reasons) supports indexing into strings
via offsets using the same syntax as array indexing, the example above
leads to a problem: should $a become an array with its first element
being "f", or should "f" become the first character of the string
$a?
The current versions of PHP interpret the second assignment as a string
offset identification, so $a becomes "f", the result of this
automatic conversion however should be considered undefined. PHP 4
introduced the new curly bracket syntax to access characters in
string, use this syntax instead of the one presented above:
Choose your rating:
Post Ans. View More Ans.
What is the difference between Reply-to and Return-path in the headers of a mail function?
[
]
Reply-to: Reply-to is where to delivery the reply of the mail.
Return-path: Return path is when there is a mail delivery failure occurs then where to delivery the failure notification.
Choose your rating:
Post Ans. View More Ans.
How to store the uploaded file to the final location?
[
]
move_uploaded_file ( string filename, string destination)
This function checks to ensure that the file designated by filename is
a valid upload file (meaning that it was uploaded via PHP's HTTP
POST upload mechanism). If the file is valid, it will be moved to the
filename given by destination.
If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
If filename is a valid upload file, but cannot be moved for
some reason, no action will occur, and move_uploaded_file() will return
FALSE. Additionally, a warning will be
Choose your rating:
Post Ans. View More Ans.
What type of headers have to be added in the mail function to attach a file?
[
]
$boundary = '--' . md5( uniqid ( rand() ) );
$headers = "From: \"Me\"\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
Choose your rating:
Post Ans. View More Ans.
List out different arguments in PHP header function?
[
]
void header ( string string [, bool replace [, int http_response_code]])
Choose your rating:
Post Ans. View More Ans.