Found 26504 Articles for Server Side Programming

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

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

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

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

316 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

424 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

576 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

How can I most efficiently check for the existence of a single value in an array of thousands of values in PHP?

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

108 Views

A quick way of doing this has been shown below −if (array_flip($set)[$value] !== null) {    echo "something"; //take some action }To customize the number of keys, the function can be customized in the below manner −function array_keys_exists(array $keys, array $arr) {    return !array_diff_key(array_flip($keys), $arr); }

Send multiple data with ajax in PHP

AmitDiwan
Updated on 06-Apr-2020 08:26:11

6K+ Views

Data can be sent through JSON or via normal POST. Following is an example showing data sent through JSON −var value_1 = 1; var value_2 = 2; var value_3 = 3; $.ajax({    type: "POST",    contentType: "application/json; charset=utf-8",    url: "your_url_goes_here",    data: { data_1: value_1, data_2: value_2, data_3: value_3 },    success: function (result) {       // perform operations here    } });With normal post, the below code can be used −$.ajax({    type: "POST",    url: $('form').attr("action"),    data: $('#form0').serialize(),    success: function (result) {       // perform operations here    } });An ... Read More

Get unix timestamp from string without setting default timezone in PHP

AmitDiwan
Updated on 06-Apr-2020 08:23:28

572 Views

String has a time zone, and there is usually no need to set a default time zone. But when it needs to be printed, the default time zone can be set explicitly. Below is the code to do the same −Default timezoneExample Live Demoecho date_default_timezone_get();OutputThis will produce the following output −UTCWhen timezone is specifiedExample Live Demoecho date("Y-m-d H:i:s",strtotime("1/1/2020 00:00:00 America/Los_Angeles"));OutputThis will produce the following output −2020-01-01 08:00:00 Another way of specifying timezoneExample Live Demoecho date("Y-m-d H:i:s",strtotime("1/1/2020 00:00:00"));OutputThis will produce the following output −2020-01-01 00:00:00

Run a Python program from PHP

SaiKrishna Tavva
Updated on 10-Sep-2024 16:38:20

7K+ Views

In PHP, the 'exec()' or 'shell_exec’ function can be used. It can be executed via the shell and the result can be returned as a string. It returns an error if NULL is passed from the command line or returns no output at all. 'exec()' Function The exec function is used for executing commands in the shell and command line of an external program and optinally capture the last line of the output. Syntax exec(string $command, array &$output = null, int &$return_var = null); 'shell_exec()' Function The shell_exec is similiar to exec but it captures and return the ... Read More

How to effectively hide Href From a Link in PHP?

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

778 Views

This is not possible. A href can’t be hidden from a link. But the files can be rewritten and the request URL can be changed to look like this − name.php/5001Other than this, a post request can be used in the below way − Go This will expose a single button in the browser.

Advertisements