We will use the built-in function Show
The built-in function 2mandatoryIt is the 3 containing the path with file name and extension. We will extract path info from this 3. 5optionalThis parameter specifies the path elements. For example, if we want to find a file name only, we can pass 6 as an option. The other options are 7, 8, and 9.This function returns an associative array containing a directory name, base name, extension, and file name. If the 0 parameter is passed, it returns a string.The program below shows can we use the
We have passed the 0 parameter. The function has returned a string containing file extension.Output: If we don’t pass the 0 parameter, the function will return an associative array.
Output:
Use 4 Construct and 5 Function to Get File Extension in PHPIn PHP, we can also use 4 construct to get the file extension. This construct will create a new SplFileInfo object. After that we can use 5 function to get the file extension. The correct syntax to use this construct is as follows:
The construct 4 accepts one parameter. The detail of its parameter is as followsParametersDescription 2mandatoryIt is the 3 that contains our file’s path. We will use this string to extract file extension.We will use 5 function to get the file extension. The correct syntax to use this function is as follows: File handling is an important part of any web application. You often need to open and process a file for different tasks. PHP Manipulating FilesPHP has several functions for creating, reading, uploading, and editing files. Be careful when manipulating files! When you are manipulating files you must be very careful.You can do a lot of damage if you do something wrong. Common errors are: editing the wrong file, filling a hard-drive with garbage data, and deleting the content of a file by accident. PHP readfile() FunctionThe Assume we have a text file called "webdictionary.txt", stored on the server, that looks like this: AJAX = Asynchronous JavaScript and XML The PHP code to read the file and write it to the output buffer is as follows (the The The next chapters will teach you more about file handling. PHP ExercisesTest Yourself With ExercisesExercise:Assume we have a file named "webdict.txt", write the correct syntax to open and read the file content.
|