Found 26504 Articles for Server Side Programming

order_of_key() in C++

Ayush Gupta
Updated on 06-Apr-2020 13:51:29

829 Views

In this tutorial, we will be discussing a program to understand order_of_key() in C++.The function order_of_key() takes in a key and returns the number of elements which are less than the key provided as parameter in an ordered set.Example Live Demo#include using namespace std; #include #include #include #include using namespace __gnu_pbds; using namespace std; //initializing ordered set typedef tree    ordered_set; int main(){    ordered_set mySet;    mySet.insert(5);    mySet.insert(2);    mySet.insert(6);    mySet.insert(4);       cout

Convert all types of smart quotes with PHP

AmitDiwan
Updated on 06-Apr-2020 09:26:09

828 Views

The below lines of code can be used, wherein UTF-8 input is expected.$chr_map = array(    // Windows codepage 1252    "\xC2\x82" => "'", // U+0082⇒U+201A single low-9 quotation mark    "\xC2\x84" => '"', // U+0084⇒U+201E double low-9 quotation mark    "\xC2\x8B" => "'", // U+008B⇒U+2039 single left-pointing angle quotation mark    "\xC2\x91" => "'", // U+0091⇒U+2018 left single quotation mark    "\xC2\x92" => "'", // U+0092⇒U+2019 right single quotation mark    "\xC2\x93" => '"', // U+0093⇒U+201C left double quotation mark    "\xC2\x94" => '"', // U+0094⇒U+201D right double quotation mark    "\xC2\x9B" => "'", // U+009B⇒U+203A single right-pointing angle ... Read More

How do you pass objects by reference in PHP 5?

AmitDiwan
Updated on 06-Apr-2020 09:19:56

391 Views

A PHP reference is an alias, that allows two different variables to write it to the same value. In PHP version 5, an object variable doesn't contain the object itself as its value. It holds an object identifier that allows object accessors to find the actual object.When an object is sent by an argument, returned or assigned to a different variable, these different variables are not aliases. They contain a copy of the identifier, that points to the same object.Example$my_var = new class_name; echo $my_var->get_class_name(5)->value; $my_var->test(); echo $my_var->get_class_name(5)->value;OutputThis will produce the following output −class_name #5This isn't "pass by reference". It ... Read More

How to find PHP execution time?

AmitDiwan
Updated on 06-Apr-2020 09:18:38

314 Views

In PHP version 7+, the getrusage function can be used. Below is a sample code demonstration −Example Live Demo//beginning of the script $exec_start = getrusage(); //other code functionalities //end of the script function rutime($ru, $rus, $index) {    return ($ru["ru_$index.tv_sec"]*1000 + intval($ru["ru_$index.tv_usec"]/1000))    - ($rus["ru_$index.tv_sec"]*1000 + intval($rus["ru_$index.tv_usec"]/1000)); } $ru = getrusage(); echo "The process used " . rutime($ru, $exec_start, "utime") .    " ms for the computations"; echo "Spent " . rutime($ru, $exec_start, "stime") .    " ms during system calls";Note − There is no need to calculate the time difference if a php instance is spawned for every test.OutputThis will ... Read More

What is faster: many ifs, or else if in PHP?

AmitDiwan
Updated on 06-Apr-2020 09:14:44

817 Views

An else if is a better option.Below is a sample code for multiple if statements −if(condition_A){    //perform some action } if(condition_B){    //perform some action }Below is a sample code for else if statement −if(condition_A){    //perform some action } else if(condition_B){    //perform some action }When else if statements are used, if a condition is satisfied, the checking stops there and the operations associated with the condition are executed. This way, the operations and conditions get over quickly.

In php, is 123==0123?

AmitDiwan
Updated on 06-Apr-2020 09:13:40

595 Views

The answer is No. This is because 0123 means 123 with base 8 (an octal number) and its equivalent in decimal is 83.Prefixing a number with 0 indicates that it is an octal (base 8) number. This is similar to the fact that 0x indicates hex (base 16) numbers.Consider the below lines of code −Example Live Demovar_dump(123); var_dump(0123);OutputThis will produce the following output −int 123 int 83This is due to the fact that 0123 is an octal notation (notice the 0 at the beginning), whereas 123 is a decimal number.Now consider the below code −Examplevar_dump(79); var_dump(079);OutputThis will produce the following output ... Read More

Stripping last comma from a foreach loop in PHP?

AmitDiwan
Updated on 06-Apr-2020 09:09:58

894 Views

Below is the code that can be used to strip the last comma from the foreach loop −Example Live Demo$result_str = array("Hi", "Hello", "have a", "good day"); foreach ($results as $result) {    $result_str[] = $result->name; } echo implode(",",$result_str);OutputThis will produce the following output −Hi,Hello,have a,good day

How can I send radio button value in PHP using JavaScript?

AmitDiwan
Updated on 06-Apr-2020 09:08:24

358 Views

ID has to be unique in a document −var option_avail = $('input[name=option_avail]:checked', '#controls').val()     firstoption     secondoption     thirdoption

Split string into sentences using regex in PHP

AmitDiwan
Updated on 06-Apr-2020 09:07:19

439 Views

Example Live Demofunction sentence_split($text) {    $before_regexes =       array('/(?:(?:[\'\"„][\.!?…][\'\"”]\s)|(?:[^\.]\s[A-Z]\.\s)|(?:\b(?:St|Gen|Hon|Prof|Dr|Mr|Ms|Mrs|[JS]r|Col|Maj|Brig|Sgt|Capt|Cmnd|Sen|Rev|Rep|Revd)       \.\s)|(?:\b(?:St|Gen|Hon|Prof|Dr|Mr|Ms|Mrs|[JS]r|Col|Maj|Brig|Sgt|Capt|Cmnd|Sen|Rev|Rep|Revd)\.\s[A-Z]\.\s)|(?:\bApr\.\s)|(?:\bAug\.\s)|(?:\bBros\.       \s)|(?:\bCo\.\s)|(?:\bCorp\.\s)|(?:\bDec\.\s)|(?:\bDist\.\s)|(?:\bFeb\.\s)|(?:\bInc\.\s)|(?:\bJan\.\s)|(?:\bJul\.\s)|(?:\bJun\.\s)|(?:\bMar\.\s)|(?       :\bNov\.\s)|(?:\bOct\.\s)|(?:\bPh\.?D\.\s)|(?:\bSept?\.\s)|(?:\b\p{Lu}\.\p{Lu}\.\s)|(?:\b\p{Lu}\.\s\p{Lu}\.\s)|(?:\bcf\.\s)|(?:\be\.g\.\s)|(?:\besp       \.\s)|(?:\bet\b\s\bal\.\s)|(?:\bvs\.\s)|(?:\p{Ps}[!?]+\p{Pe} ))\Z/su',    '/(?:(?:[\.\s]\p{L}{1, 2}\.\s))\Z/su',    '/(?:(?:[\[\(]*\.\.\.[\]\)]* ))\Z/su',       '/(?:(?:\b(?:pp|[Vv]iz|i\.?\s*e|[Vvol]|[Rr]col|maj|Lt|[Ff]ig|[Ff]igs|[Vv]iz|[Vv]ols|[Aa]pprox|[Ii]ncl|Pres|[Dd]ept|min|max|[Gg]ovt|lb|ft|c\.?\s       *f|vs)\.\s))\Z/su',    '/(?:(?:\b[Ee]tc\.\s))\Z/su',    '/(?:(?:[\.!?…]+\p{Pe} )|(?:[\[\(]*…[\]\)]* ))\Z/su',    '/(?:(?:\b\p{L}\.))\Z/su',    '/(?:(?:\b\p{L}\.\s))\Z/su',    '/(?:(?:\b[Ff]igs?\.\s)|(?:\b[nN]o\.\s))\Z/su',    '/(?:(?:[\"”\']\s*))\Z/su',    '/(?:(?:[\.!?…] [\x{00BB}\x{2019}\x{201D}\x{203A}\"\'\p{Pe}\x{0002}]*\s)|(?:\r?))\Z/su',    '/(?:(?:[\.!?…] [\'\"\x{00BB}\x{2019}\x{201D}\x{203A}\p{Pe}\x{0002}]*))\Z/su',    '/(?:(?:\s\p{L}[\.!?…]\s))\Z/su');    $after_regexes = array('/\A(?:)/su',    '/\A(?:[\p{N}\p{Ll}])/su',    '/\A(?:[^\p{Lu}])/su',    '/\A(?:[^\p{Lu}]|I)/su',    '/\A(?:[^p{Lu}])/su',    '/\A(?:\p{Ll})/su',    '/\A(?:\p{L}\.)/su',    '/\A(?:\p{L}\.\s)/su',    '/\A(?:\p{N})/su',    '/\A(?:\s*\p{Ll})/su',    '/\A(?:)/su',    '/\A(?:\p{Lu}[^\p{Lu}])/su',    '/\A(?:\p{Lu}\p{Ll})/su'); $is_sentence_boundary = array(false, false, false, false, false, false, ... Read More

How to upload large files above 500MB in PHP?

AmitDiwan
Updated on 06-Apr-2020 09:01:55

12K+ Views

Large files can be uploaded using PHP in two ways. Both of them are discussed below −By changing the upload_max_filesize limit in the php.ini file.By implementing file chunk upload, that splits the upload into smaller pieces an assembling these pieces when the upload is completed.The php.ini file can be updated as shown below −upload_max_filesize = 50M post_max_size = 50M max_input_time = 300 max_execution_time = 300This should be avoided since it would change the settings of the server and other projects too.Updating the htacess filephp_value upload_max_filesize 50M php_value post_max_size 50M php_value max_input_time 300 php_value max_execution_time 300Changing the inline setting −ChunkingIn this ... Read More

Advertisements