- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1046 Articles for PHP
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
965 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) { $data[] = array($child->nodeName => $child->nodeValue); } }OutputThis will produce the following output −Every ‘foo’ tag will be iterated over and specific ‘bar’ and ‘pub’ value will be obtained, i.e specific child nodes can be accessed by their names itself.The elements in the XML file are obtained by ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
583 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 message generated by the expression will be saved in the variable named $php_errormsg. This variable will be overwritten each time on every error.It is always suggested to write code that works relevantly with error states/conditions.
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
465 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 with the specific namespace can be obtained using ‘get_declared_classes’. Simply put, this data obtained can be used to find a matching namespace given all the declared class names −function namespaceExists($namespace) { $namespace .= "\"; foreach(get_declared_classes() as $name) if(strpos($name, $namespace) === 0) return true; return false; }----Or---Example Live Demo
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
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 and saved with the same name. This way, the file will be overwritten, and new changes will be reflected in the file.Exampleerror_reporting(E_ALL); set_time_limit(0); date_default_timezone_set('Europe/London'); set_include_path(get_include_path() . PATH_SEPARATOR . './Classes/'); include 'PHPExcel/IOFactory.php'; $fileType = 'Excel5'; $fileName = name_of_file.xls'; // Read the file $objReader = PHPExcel_IOFactory::createReader($fileType); $objPHPExcel = $objReader->load($fileName); // Change the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
736 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 otherwise −Example Live DemoOutputThis will produce the following output −Sorry, the file could not be openedThe ‘file_get_contents’ function is an inbuilt function in PHP that loads the file into memory and displays the contents only when the echo function is called. During this phase, the data is copied from memory to ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
4K+ 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 can be stored in a file, a memory buffer or can be transferred over a network.Using the serialize function to store the object −session_start(); $object = new sample_object(); $_SESSION['sample'] = serialize($object);The session is started by using the ‘session_start’ function and a new object is created. The object created is serialized ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ 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)) { $combinations = $chars; } # size 1 indicates we are done if ($size == 1) { return $combinations; } # initialise array to put new values into it $new_combinations = array(); # loop through the existing combinations and ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
404 Views
Yes, debuggers like XDebug reduce the performance of the PHP server. This is the reason why debuggers are not placed in server environment. They are deployed in a different environment to avoid unnecessary overheads.Debug messages can’t be displayed in an application that is already in the production phase.When debugging behavior is added to the server, the debug engine gets attached to the PHP process. It starts to receive messages to stop at breakpoint, but this is not the required behavior, since it introduces a high-performance blow to other processes thereby stopping the PHP parser.On the other hand, when a debugger ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
316 Views
The regular expression [\S\s]* in PHP means “don’t match new lines”.In PHP, the /s flag can be used to make the dot match all the characters −Example Live Demoprint(preg_match('/^[\S\s]$/s',"hello world"));OutputThis will produce the following output −0The ‘preg_match’ function is used to match regular expression with the given input string. Here since the ‘\’ is encountered, it returns 0.