Wednesday, November 12, 2008

Question: What is the difference between the functions unlink and unset?

Question: What is the difference between the functions unlink and unset?
Answer:
unlink will delete a file and unset would remove a value from a session variable.

Question: What is meant by urlencode and urldecode?

Question: What is meant by urlencode and urldecode?

Answer:
string urlencode(str) where str contains a string for example “hello world” and the return value will be URL encoded and can be use to append with URLs‚ normaly used to appned data for GET like someurl.com?var=hello%world string urldocode(str) this will simply decode the GET variable’s value for example

echo (urldecode($_GET_VARS[var])) will output “Hello world”

Question: What is the functionality of the function strstr and stristr?

Question: What is the functionality of the function strstr and stristr?
Answer:
string strstr (string str1‚ string str2) this function search the string str1 for the first occurrence of the string str2 and returns the part of the string str1 from the first occurrence of the string str2. This function is case-sensitive and for case-insensitive search use stristr() function.


Example of strstr: $email = ’name@example.com’;
$domain = strstr($email‚ ’@’); echo $domain; // prints @example.com $user = strstr($email‚ ’@’‚ true); echo $user; // prints name ?>

Example of stristr: $email = ’USER@EXAMPLE.com’; echo stristr($email‚ ’e’); // outputs ER@EXAMPLE.com echo stristr($email‚ ’e’‚ true); // outputs US ?>

Question: What are the different types of errors in PHP?

Question: What are the different types of errors in PHP?

Answer:
Three are three types of errors:

1) Fatal errors.

2) Parser errors.

3) Startup errors.

Question: How can we encrypt the username and password using PHP?

Question: How can we encrypt the username and password using PHP?

Answer:
PHP has an md5 function that would normally suffice. Also‚ since the password function in mysql can change between versions‚ using PHP’s md5 function would be better here. As an aside‚ concatonating the record id (or something else handy) before hashing will stop different users with the same password getting the same hash.

Question: What is meant by nl2br()?

Question: What is meant by nl2br()? Answer:
nl2br() inserts html in string.

Example: echo nl2br(”god bless \n you”);
output: god bless you

Question: Suppose your Zend engine supports the mode Then how can u configure your PHP Zend engine to support mode?

Question: Suppose your Zend engine supports the mode Then how can u configure your PHP Zend engine to support mode?
Answer:
In php.ini file: set short_open_tag=on

Question: How can I execute a PHP script using command line?

Question: How can I execute a PHP script using command line?
Answer:
For command line‚ we have to use php CLI(command line interface).

Question: Can we use include ("abc.php") two times in a php page "makeit.php"?

Question: Can we use include ("abc.php") two times in a php page "makeit.php"?
Answer:
Yes‚ and we can use it more then two times.

Question: What are the differences between require and include‚ include_once?

Question: What are the differences between require and include‚ include_once?
Answer:
require_once()‚include_once() both the functions include and evalute the specified file only once and if the specified file is opened previous to the present call occurrance‚ it will not be done again. But require() and include() will do it as many times they are asked to do. The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement‚ with the only difference being that if the code from a file has already been included‚ it will not be included again. The major difference between include() and require() is that in failure include produces a warning message whereas require produces a Fatal errors.

Question: How can we create a database using php and mysql?

Question: How can we create a database using php and mysql?

Answer: mysql_create_db()

Example:

$link = mysql_connect(’localhost’‚ ’mysql_user’‚ ’mysql_password’);

if (!$link)

    {

        die(’Could not connect: ’ . mysql_error());

    }

$sql = ’CREATE DATABASE my_db’;

if (mysql_query($sql‚ $link))

    {

        echo "Database my_db created successfully\n";

    }

else

    {

        echo ’Error creating database: ’ . mysql_error() . "\n";

    }

?>

security header validate

  HTTP Security Headers Check Tool - Security Headers Response (serpworx.com)