Programming Articles - Page 2037 of 3363

Connect to external server by using phpMyAdmin

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

331 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.

Which is better PHP SOAP or NuSOAP?

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

398 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

How to use __dir__ in PHP?

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 "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

How to set a verbose mode in JShell in Java 9?

raja
Updated on 06-Apr-2020 09:04:52

473 Views

JShell is the REPL tool that has introduced in Java 9. We can use this tool to execute simple snippets in the command-line prompt.When we enter an arithmetic expression, variable, etc in JShell, then it displays the result without details of the type of variable created. It is possible in JShell to display more information about the execution of an entered command, use verbose mode. We need to obtain more information on the commands executed by using the command: "/set feedback verbose" (the command can be preceded by "/").In the below snippet, the verbose mode is on, and it can able to ... Read More

How do I chain methods in PHP?

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
Updated on 06-Apr-2020 08:36:32

455 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\[ \]

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

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

349 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

Calling Stored Procedure inside foreach PHP Codeigniter

AmitDiwan
Updated on 06-Apr-2020 08:33:34

1K+ Views

The code inside the 'Model' and the 'Controller' needs to be changed to include code that is shown below −Inside the 'Controller'$header = $this->model_name->call_head(); foreach($header as $item) {    $name = $item['name'];    $array['name'] = $name;    $array['data'] = $item['data'];    $child_val = $this->model_name->call_child($name);    foreach($child_val as $value) {       $array['child'] = array(          'child_name' => $value['child_name'],          'child_data' => $value['child_data']       );    } }Inside the 'model'public function call_head() {    $query = "CALL PROCEDURE_HEAD()";    $result = $this->db->query($query)->result_array();    $query->next_result();    $query->free_result();    return $result; } public function ... Read More

Converting JSONL to Array with PHP

AmitDiwan
Updated on 06-Apr-2020 08:31:12

442 Views

The json_decode function can be used as shown below −json_decode($json_string_that_needs_to_be_converted, true);The below lines of code can be used to convert JSONL to array format −$json_string = '["m@gmail.com", "p@gmail.com", "q@gmail.com"]'; $array_of_data=json_decode($json_string);An alternate is to use the below code, wherein the way json_string has been defined changes −Example$json_string = "[\"m@gmail.com\", \"p@gmail.com\", \"q@gmail.com\"]"; $array_of_data=json_decode($json_string);OutputThis will produce the following output −Array("m@gmail.com", "p@gmail.com", "q@gmail.com")Read More

PHP function to convert Hex to HSL

AmitDiwan
Updated on 06-Apr-2020 08:29:57

593 Views

The below code can be used to convert hex value into HSL value −function hex_To_Hsl($hex) {    $hex_val = array($hex_val[0].$hex_val[1], $hex_val[2].$hex_val[3], $hex_val[4].$hex_val[5]);    $rgb_val = array_map(function($part) {       return hexdec($part) / 255;    }, $hex_val);    $max_val = max($rgb_val);    $min_val = min($rgb_val);    $l = ($max_val + $min_val) / 2;    if ($max_val == $min_val) {       $h = $s = 0;    } else {       $diff = $max_val - $min_val;       $s = $l > 0.5 ? $diff / (2 - $max_val - $min_val) : $diff / ($max_val + ... Read More

Advertisements