- 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)
3K+ Views
The fopen, fread and fwrite functions can be used to open a file stream, read a data stream and write that data to a file respectively.The file resource doesn't necessarily need to point to a location on the local machine itself.Below is an example that transfers a file from the local server to ftp server −$file = "file_name.jpg"; $destination = fopen("ftp://username:password@example.com/" . $file, "wb"); $source = file_get_contents($file); fwrite($destination, $source, strlen($source)); fclose($destination);The image needs to be transferred to an FTP server. Hence the server is opened in write mode, and the image is written to that location and the stream is ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
193 Views
Constants in PHP are defined using the 'define' function. They are fairly slow in PHP.There are instances where extensions (such as hidef) were written to improve the performance of the code.This comes into picture when there are thousands of constants.Beginning from PHP version 5.3, compile-time constants with the help of const NAME = VALUE; can also be used. They are relatively quicker.
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
532 Views
Serialize is better in comparison to JSON to store PHP variables.The var_export can be used to save config file, and 'include' can be used to load the config file information.This is an easy way to save config data programmatically and easier to read/write. Below is a sample code for the same −config.phpreturn array( 'var_1'=> 'value_1', 'var_2'=> 'value_2', );test.php$config = include 'config.php'; $config['var_2']= 'value_3'; file_put_contents('config.php', '
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
424 Views
The reply and return path can be placed in the headers as shown below −$headers = 'From: sample@example.com' . "\r" . 'Reply-To: sample@example.com' . "\r" . 'Return-Path: sample@example.com'Otherwise, it can be passed as the fifth parameter to change the return path −mail($to, $subject, $message, $headers, "-f email@wherever.com");Here, 'email@wherever.com' has to be replaced with the user's respective email id.
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
203 Views
The below lines of code can be added to the /etc/phpmyadmin/config.inc.php file at the bottom −$i++; $cfg['Servers'][$i]['host'] = 'HostName:port'; // hostname and port are provided if they are not default values $cfg['Servers'][$i]['user'] = 'userName'; //user name for the remote server $cfg['Servers'][$i]['password'] = 'Password'; //the password $cfg['Servers'][$i]['auth_type'] = 'config';It will display “Current Server:” with drop down of both "127.0.0.1" and the one provided with $cfg['Servers'][$i]['host'].The user can switch between both the servers.
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
265 Views
PHP SOAP has been made available beginning from PHP version 5.0.1 . Users who are still using PHP4 need to use NuSOAP.Native PHP codes are better in terms of performance & relatively bug free. Hence it is suggested to use PHP SOAP if it is available.On the other hand, NuSOAP doesn't have much documentation on their official website as well.Salient features of NuSOAPIt comes with a few predefined methods whereas they need to be written on one's own in case of Soap.The performance metric for SOAP is server response time.Handling UTF-8 is much easier in Nusoap.Nusoap offers certain functions that ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
21K+ Views
The __DIR__ can be used to obtain the current code working directory. It has been introduced in PHP beginning from version 5.3. It is similar to using dirname(__FILE__). Usually, it is used to include other files that is present in an included file.Consider the following directory structure −A directory called "master", that has two files named 'worker_1', and 'worker_2'. The master directory itself is a subfolder of the main project directory.The project directory also contains an index.php file.Consider having two files in a directory called inc, which is a subfolder of our project's directory, where the index.php file lies −project_directory ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
The mutator methods can be used to chain methods, wherein these methods return the original objects, and other methods can be called on these objects that are returned by the mutator functions.ExampleBelow is a simple example demonstrating the same − Live Demo
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
334 Views
The addcslashes function can be used. Below is the syntax of the function −string addcslashes ( string $str, string $charlist )This function returns a string with backslashes that appear before the characters. Below is a demonstration of the function.Example Live DemoOutputThis will produce the following output −\s\a\m\p\l\e\[ \]
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
216 Views
The reason behind in_array returning True could be the string-to-number conversion. When a string is passed to the function, it returns 0, which is the value that needs to be searched for.PHP uses loose juggling, i.e. using == instead of === when elements are compared. Hence, their values are compared and not the types.Another reason is type juggling, which means a variable type is dealt with in the context of the code.For example- when a float value is assigned to a variable, it becomes a floating-point value. It behaves in a way when a string is casted to an integerTo ... Read More