Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
AmitDiwan has Published 10740 Articles
AmitDiwan
681 Views
To read only 5 last lines of the text file, the code is as follows −Example$file = file("filename.txt"); for ($i = max(0, count($file)-6); $i < count($file); $i++) { echo $file[$i] . ""; }OutputThis will produce the following output −Given that the file has more than 5 lines of text, ... Read More
AmitDiwan
3K+ Views
To download large files through PHP script, the code is as follows −ExampleOutputThis will produce the following output −The large file will be downloaded.The function ‘readfile_chunked’ (user defined) takes in two parameters- the name of the file and the default value of ‘true’ for the number of bytes returned meaning ... Read More
AmitDiwan
334 Views
Most of the core PHP functions don’t deal with character sets apart from Latin-1. But before the ‘pathinfo’, placing the ‘setlocale’ can be used to return the correct filename even if it is UTF-8 encoded.By default, it runs with ‘C’ locale, and CLI scripts run with a default utf-8 locale. ... Read More
AmitDiwan
1K+ Views
Following is the XML data (input) − Iterating through the elements in the DOM object.Example$elements = $dom->getElementsByTagName('foo'); $data = array(); foreach($elements as $node){ foreach($node->childNodes as $child) { ... Read More
AmitDiwan
785 Views
The ‘@’ symbol suppresses errors from getting displayed on the screen.PHP supports an error control operator, i.e the sign (@). When it is prepended to an expression in PHP, error messages that could get generated when it uses that expression will be ignored.If the track_errors attribute is enabled, the error ... Read More
AmitDiwan
686 Views
Given file 1 has namespace ns_1 and file 2 has namespace ns_2, if file 1 and file 2 are included in file 3, there is no way to know that namespaces ns_1 and ns_2 have been loaded.The only way is to use the ‘class_exists’ function and the list of classes ... Read More
AmitDiwan
3K+ Views
There is no concept of opening a file for read and write in PHPExcel since it is not aware of the source of the PHPExcel object. Irrespective of the source from where the file was loaded or the type of file, the file can be read based on its named ... Read More
AmitDiwan
1K+ Views
The ‘readfile’ function is an inbuilt function in PHP that reads the file directly into the output buffer. The name of the file is passed as a parameter to the function. It returns the number of bytes that were read in case of successfully reading the data. It returns FALSE ... Read More
AmitDiwan
5K+ Views
The serialize() function in PHP can be used before storing the object, and the unserialize() function can be called when the object needs to be retrieved from the session.The function converts a storable representation of a specific value into a sequence of bits. This is done so that the data ... Read More
AmitDiwan
2K+ Views
To generate all combinations of a specific size from a single set, the code is as follows −Example Live Demofunction sampling($chars, $size, $combinations = array()) { # in case of first iteration, the first set of combinations is the same as the set of characters if (empty($combinations)) { ... Read More