Splunk Technology PHP Most Frequently Asked Latest Interview Questions Answers

Click here to get this post in PDF

Splunk Technology PHP Most Frequently Asked Latest Interview Questions Answers

If you run this script again, it will print: Directory does not exist. Splunk Technology PHP Most Frequently Asked Latest Interview Questions Answers How To Remove A File? If you want to remove an existing file, you can use the unlink() function. Here is a PHP script example on how to use unlink():<?php print("File does not exist.n"); } If you run this script again, it will print: File does not exist. How To Copy A File? If you have a file and want to make a copy to create a new file, you can use the copy() function. Here is a PHP script example on how to use copy():<?php print("A copy of ping.exe is created.n"); } A copy of ping.exe is created. 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(): Size of the file: 7116 How To Open A File For Reading? If you want to open a file and read its contents piece by piece, you can use the fopen($fileName, “r”) function. It opens the specified file, and returns a file handle. The second argument “r” tells PHP to open the file for reading. Once the file is open, you can use other functions to read data from the file through this file handle. Here is a PHP script example on how to use fopen() for reading:<?php print("Type of file handle: " . gettype($file) . "n"); print("The first line from the file handle: " . fgets($file)); fclose($file); Type of file handle: resource The first line from the file handle: # Copyright (c) 1993-1999 Note that you should always call fclose() to close the opened file when you are done with the file. How To Open A File For Writing? If you want to open a new file and write date to the file, you can use the fopen($fileName, "w") function. It creates the specified file, and returns a file handle. The second argument "w" tells PHP to open the file for writing. Once the file is open, you can use other functions to write data to the file through this file handle. Here is a PHP script example on how to use fopen() for writing:<?php fwrite($file,"Download PHP scripts at dev.pickzycenter.com.rn"); fclose($file); This script will write the following to the file: Download PHP scripts at dev.pickzycenter.com. Note that you should use "rn" to terminate lines on Windows. On a Unix system, you should use "n". How To Read One Character From A File? If you have a text file, and you want to read the file one character at a time, you can use the fgetc() function. It reads the current character, moves the file pointer to the next character, and returns the character as a string. If end of the file is reached, fgetc() returns Boolean false. Here is a PHP script example on how to use fgetc():<?php Note that rtrim() is used to remove "n" from the returning string of fgets(). How To Read A File In Binary Mode? If you have a file that stores binary data, like an executable program or picture file, you need to read the file in binary mode to ensure that none of the data gets modified during the reading process. You need to:•Open the file with fopen($fileName, "rb").•Read data with fread($fileHandle,$length). Here is a PHP script example on reading binary file: This script will print: About 16448 bytes read. This script actually copied an executable program file ping.exe in binary mode to new file. The new file should still be executable. How To Open Standard Output As A File Handle? If you want to open the standard output as a file handle yourself, you can use the fopen(“php://stdout”) function. It creates a special file handle linking to the standard output, and returns the file handle. Once the standard output is opened to a file handle, you can use fwrite() to write data to the starndard output like a regular file. Here is a PHP script example on how to write to standard output:<?php fwrite($stdout,"Looking for PHP hosting provider!n"); fclose($stdout); To do: Looking for PHP hosting provider! If you don't want to open the standard output as a file handle yourself, you can use the constant STDOUT predefined by PHP as the file handle for standard output. If you are using your script in a Web page, standard output is merged into the Web page HTML document. print() and echo() also writes to standard output. How To Get The Directory Name Out Of A File Path Name? If you have the full path name of a file, and want to get the directory name portion of the path name, you can use the dirname() function. It breaks the full path name at the last directory path delimiter (/) or (), and returns the first portion as the directory name. Here is a PHP script example on how to use dirname():<?php print("File full path name: $pathNamen"); print("File directory name: $dirNamen"); print("n"); File full path name: /temp/download/todo.txt File directory name: /temp/download What is the correct and the most two common way to start and finish a PHP block of code? The two most common ways to start and finish a PHP script are: and How can we display the output directly to the browser? To be able to display the output directly to the browser, we have to use the special tags . What is the main difference between PHP 4 and PHP 5? PHP 5 presents many additional OOP (Object Oriented Programming) features. How To Break A File Path Name Into Parts? If you have a file name, and want to get different parts of the file name, you can use the pathinfo() function. It breaks the file name into 3 parts: directory name, file base name and file extension; and returns them in an array. Here is a PHP script example on how to use pathinfo():<?php ) How To Create A Web Form? If you take input data from visitors on your Web site, you can create a Web form with input fields to allow visitors to fill in data and submit the data to your server for processing. A Web form can be created with the

tag with some input tags. The &FORM tag should be written in the following format:

Where “processing.php” specifies the PHP page that processes the submitted data in the form. What Are Form Input Html Tags? HTML tags that can be used in a form to collect input data are:• – Displayed as a button allow users to submit the form.• – Displayed as an input field to take an input string.• – Displayed as a radio button to take an input flag.• – Displayed as a checkbox button to take an input flag.• – Displayed as a dropdown list to take input selection.•