Writing into the file in PHP

The code below overwrites existing content in a file:
$handle = fopen($filename, 'w') or die('Cannot open file:  '.$filename);
The code below adds new line to the existing content:
$handle = fopen($filename, 'a') or die('Cannot open file:  '.$filename);
So, the difference is in fopen($filename, 'w') and fopen($filename, 'a')

Auth in Laravel

For logging system in Laravel I can do this: 1. Win logo on keyboard + R. 2. Type cmd. 3. Go to my Laravel's folder (cd + folder name/or cd.. for moving directory up ) 4. php artisan make:auth

Get the title in default language

Sometimes we need variables to stay in a default language, e.g in English. For example, we have a multi-language site but Google Maps accepts country's name only in English. In our php-part:
if (ICL_LANGUAGE_CODE!="en"){
   $original_ID = icl_object_id( $post->ID, 'post', false, 'en' );
   $country = get_the_title( $original_ID );
   
  } else {
       $country = $country_full_name;
  }
And in our HTML-part:

Change categories’ order

Needed the categories to be in certain order - not in alphabetical and not by id. It can be done by some plugin, but here is the way also through code:
 // change order of terms
   	function gto_forced_order($orderby) {

             switch (ICL_LANGUAGE_CODE){
   	      case("de"):
    	         $orderby = "FIELD(t.term_id, 465, 468,524,525,574,575, 600, 601,1240, 775, 777, 778, 841,843, 844)";
    	      break;
   	      case("fr"):
    	         $orderby = "FIELD(t.term_id,183, 184,203,204, 218, 219, 230, 231, 1239, 294, 296, 297, 306, 308,309)";
    	      break;
   	      case("ru"):
    	        $orderby "FIELD(t.term_id,954,955,974,975,989,990,1041,1042,1241,1145,1147,1375,1184,1186,1187)";
    	      break;
              case("es"):
    	         $orderby = "FIELD(t.term_id,834, 935,994,995,1009,1010,1021,1022,1242, 1165,1167,1168,1177,1179,1180 )";
    	       break;
               case("zh-hant"):
    	           $orderby = "FIELD(t.term_id,464, 467,526,527, 569, 570,609, 610,1238,795, 797, 798, 834, 836, 837)";
    	       break;
               case("ar"):
    	         $orderby = "FIELD(t.term_id,466, 469,528,529, 579, 580,591, 592,1243,815, 817, 818, 827, 829, 830)";
    	       break;
               default: 
     	         $orderby = "FIELD(t.term_id,125,95,97,121,33,32,124,99,37,36,96,122,123,94,34)";
     	        break;
              }

 
         return $orderby;
       }
add_filter('get_terms_orderby','gto_forced_order');

//original query
$tax_terms = get_terms( $tax, $tax_args );
gto_forced_order($tax_terms);
Just change the terms' IDs. Source as usual almighty Internet.

Check if rgb(a) or hex color is in correct format

function color_format($i){
        
$pattern = "/^rgb/i";
$pattern2 ="/a/i";
 $i = strtolower($i);
//its rgb
if (preg_match($pattern, $i)){
  
      // is ending with ; 
  $no_need = substr( $i, -1 );
      // is ending with ;
    if($no_need==";") {
      $i = substr($i,0,-1);
       
    } 
    // let's split "("
       $needed_piece = explode("(", $i);
  
  //it's rgb
      if (preg_match($pattern2, $i)){
         $needed_color = "rgba(".$needed_piece[1];
      } else {
         $needed_color = "rgb(".$needed_piece[1];
      }
     
       return $needed_color;

} else{
    
   // is ending with ;
    $no_need = substr( $i, -1 );

    if($no_need==";") {
      $i = substr($i,0,-1);
       
    } 
    
    // is starting with #
 $i= ltrim($i, '#');
 if (
          ctype_xdigit($i) &&
          (strlen($i) == 6 || strlen($i) == 3))
           return $needed_color = "#".$i;


  else return false;
    

}

} 

Add/delete multiple rows in Goolge Sheets

For adding multiple rows in Google Sheets: Add 8 rows at once 1. Choose how many rows you want to add. In my example I chose eight rows. Add 8 rows at once in Google Sheets 2. Right click and it gives you a choice to add above or below. Right click and it gives you a choice to add above or below 3. I chose below and voila - it is done! Add 8 rows at once in Google Sheets You can you use the same technique for deleting rows and adding-deleting columns. Here is an animated gif of the full process: Add 8 rows at once in Google Sheets