AmitDiwan has Published 10744 Articles

Upload file with php to another php server

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 08:49:40

4K+ 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 ... Read More

Which is faster? Constants, Variables or Variable Arrays in PHP?

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 08:48:19

295 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 ... Read More

Fastest way to store easily editable config data in PHP?

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 08:47:15

655 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 ... Read More

Change the Return-Path in PHP mail function

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 08:46:09

573 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 ... Read More

Connect to external server by using phpMyAdmin

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 08:44:04

306 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'] = ... Read More

Which is better PHP SOAP or NuSOAP?

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 08:41:34

369 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 ... Read More

How to use __dir__ in PHP?

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 08:40:48

24K+ 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 ... Read More

How do I chain methods in PHP?

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 08:39:11

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

PHP: is there a way to see “invisible” characters like

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 08:36:32

427 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\[ \]Read More

Why does php's in_array return true if passed a 0?

AmitDiwan

AmitDiwan

Updated on 06-Apr-2020 08:34:48

314 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 ... Read More

Advertisements