Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
$str_time = "23:12:95";

$str_time = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $str_time);

sscanf($str_time, "%d:%d:%d", $hours, $minutes, $seconds);

$time_seconds = $hours * 3600 + $minutes * 60 + $seconds;
And if you don't want to use regular expressions:
$str_time = "2:50";

sscanf($str_time, "%d:%d:%d", $hours, $minutes, $seconds);

$time_seconds = isset($seconds) ? $hours * 3600 + $minutes * 60 + $seconds : $hours * 60 + $minutes;
by გიორგი უზნაძე
3 years ago
0
PHP
Date
Regexp
2
Case Sensitivity CODE
The three variables
$variable
,
$Variable
and
$VARIABLE
are completely different
// lowercase
$variable = "Value 1";

// PascalCase
$Variable = "Value 2";

// UPPERCASE
$VARIABLE = "Value 3";

echo $variable . "\n";
echo $Variable . "\n";
echo $VARIABLE . "\n";
Function names are case-insensitive
function printGreeting() {
	print "Prints: Hello world!\n";
}
printGreeting();
Calling the function with uppercase will still work
by Valeri Tandilashvili
2 years ago
4
PHP
Variables
2
String functions CODE
Function
strlen()
returns the length of the string
echo strlen("Hello world!")."\n"; // 12
Function
strrev()
returns the Reverse of the string
echo strrev("Hello world!")."\n"; // !dlrow olleH
Function
strpos()
tries to find the second parameter and returns its index
echo strpos("Hello world!", "world")."\n"; // 6
Function
str_replace()
replaces the word "Hello" with "Hi"
echo str_replace("Hello", "Hi", "Hello there")."\n"; // Hi there
Function
substr()
returns the substring between given indexes
echo substr("Hello world", 6)."\n"; // world
echo substr("Hello world", 6, 3)."\n"; // wor
echo substr("Hello world", -5)."\n"; // world
echo substr("Hello world", -4, 2)."\n"; // or
Function
trim()
removes whitespaces from sides of the string
echo trim("   Hello World  ").".\n"; // Hello World.
// Removes whitespaces from the right end
echo rtrim("   Hello World  ")."\n"; //    Hello World
// Removes Exclamation mark from the right end
echo rtrim("Hello World!", "!")."\n"; // Hello World
Function
strtoupper()
converts the string to upper case
echo strtoupper("Hello World")."\n";
Function
strtolower()
converts the string to lower case
echo strtolower("Hello World")."\n";
Function
explode()
breaks the string by its delimiter
print_r (explode(" ", "It's the first day of the course!"));
Function
implode()
joins the array element based on the delimiter and returns the string
echo implode(" ", ['Hello', 'World']);
by Valeri Tandilashvili
2 years ago
0
PHP
functions
2
PHP if-else statement CODE
The code will output "Have a nice weekend!" if the current day is Friday, otherwise - "Have a nice day!"
$d = date("D");
if($d == "Fri"){
    echo "Have a nice weekend!";
} else{
    echo "Have a nice day!";
}
echo "\n";
Output "Have a good day!" if the current time is less than 20, and "Have a good night!" otherwise:
$t = date("H");
if ($t < "20") {
    echo "Have a good day!";
} else {
    echo "Have a good night!";
}
If
$age
is more than
18
, prints
Adult
otherwise prints
Child
$age = 20;
if ($age > 18) {
    echo 'Adult';	
} else {
    echo 'Child';	
}
by Valeri Tandilashvili
2 years ago
0
PHP
If / else
2
User-defined functions CODE
Function that does something
function printGreeting() {
	print "Prints: Hello world!\n";
}
printGreeting();
Function that returns something
function returnGreeting() {
	return "Returns: Hello world!\n";
}
echo returnGreeting();
Parameterized function that doubles the number
function doubleMe($number) {
	$result = "$number times 2 is: " . $number * 2 . "\n";
	return $result;
}
echo doubleMe(4);
Function calculates the sum of two numbers
function add($num1, $num2) {
	$sum = $num1 + $num2;
	$result = "Sum of $num1 and $num2 is: $sum";
	return $result;
}
echo add(4, 5);
by Valeri Tandilashvili
2 years ago
0
PHP
functions
2
PHP For loop CODE
if
has only one section:
Condition
if (Condition) {
    // Code to be executed
}
for
loop has three sections divided by
;
for (Initialization;   Condition;   Increment/Decrement) {
    // Code to be executed
}
The loop prints numbers from 0 to 10
for ($i = 0;  $i < 10;  $i ++) {
	echo $i . "\n";
}
by Valeri Tandilashvili
2 years ago
0
PHP
2
IF - კოდი სრულდება, თუ პირობა ჭეშმარიტია; IF...ELSE - თუ პირველი პირობა (IF) ჭეშმარიტია დაიბეჭდება იგი, ხოლო თუ მცდარია დაიბეჭდეება მეორე კოდი; IF...ELSEIF...ELSE - ჯერ პირველი პირობა მოწმდება (IF) და სრულდება კოდი თუ ჭეშმარიტია იგი, ხოლო თუ მცდარია შემდეგ მოწმდება მეორე პირობის სისწორე(ELSEIF) და სრულდება იგი, თუ ისიც მცდარია მაშინ სრულდება ELSE კონდიცია; ახლა ვნახოთ ერთი პრაქტიკული მაგალითი:
$კამათელი1 = rand(1, 6);                                            // შემთხვევითობის პრინციპით ამოსული კამათელი 1-დან 6-მდე
$კამათელი2 = rand(1, 6);                                            // შემთხვევითობის პრინციპით ამოსული მეორე კამათელი 1-დან 6-მდე

if  ($კამათელი1 == $კამათელი2) {                                                 // I პირობა
    echo "WOOW გაგორდა წყვილი";                                                // თუ შესრულდება დაიბეჭდება ეს
    } else if ($კამათელი1 > 3 && $კამათელი2 > 3) {                                                   // მეორე პირობა
    echo "მაინც კარგი სეტია რადგან ორივე კამათელი 3-ზე მაღალია";    // თუ შესრულდა მეორე პირობა დაიბეჭდება ეს
    } else if ($კამათელი1 > 3 || $კამათელი2 > 3) {                                                       // მესამე პირობა
    echo "არაუშავს რადგან ერთი კამათელი მაინც მეტია 3-ზე";               // თუ შესრულდა მესამე პირობა დაიბეჭდება ეს
    } else {                                                                      // თუ არცერთი პირობა არ შესრულდება დაიბეჭდოს თავიდან სცადე                  
    echo "თავიდან სცადე";
    }
P.S პირობაში
&&
არის
"და"
პირობაში
||
არის
"ან"
by Luka Khitaridze
2 years ago
0
PHP
2
777 game with php
$a = rand(0, 10); $b = rand(0, 10); $c = rand(0, 10); echo " $a", " $b", " $c" . '<br>'; if($a == 7 && $b ==7 && $c== 7 ){ echo 'u won jackpot'; } elseif($a ==7 && $b!==$a && $c!==$a) { echo 'last and middel number are not 7'; } elseif($a !==$b && $b==7 && $c!==$b) { echo 'last and first number are not 7'; } elseif($a !==$c && $b!==$c && $c ==7) { echo 'middel and first number are not seven'; } elseif($a ==7 && $b==7 && $c!==$b) { echo "last number is not 7"; } elseif($a !==$b && $b==7 && $c==7) { echo "first number is not 7"; } elseif($a ==7 && $b!==$a && $c!==7) { echo 'middel number is not 7' ; } else{ echo 'try again'; }
by guga muchiashvili
2 years ago
0
PHP
php note
2
nginx virtual host laravel
Now we need to give the web server user write access to the storage and cache folders, where Laravel stores application-generated files:
sudo chown -R www-data.www-data /var/www/your_domain/storage
sudo chown -R www-data.www-data /var/www/your_domain/bootstrap/cache
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
create a new virtual host configuration file at
/etc/nginx/sites-available
:
sudo nano /etc/nginx/sites-available/your_domain
The following configuration file contains the recommended settings for Laravel applications on Nginx:
server {
    listen 80;
    server_name server_domain_or_IP;
    root /var/www/your_domain/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
Copy this content to your /etc/nginx/sites-available/travellist file and, if necessary, adjust the highlighted values to align with your own configuration. Save and close the file when you’re done editing. To activate the new virtual host configuration file, create a symbolic link to travellist in sites-enabled:
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
To confirm that the configuration doesn’t contain any syntax errors, you can use:
sudo nginx -t
You should see output like this:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
To apply the changes, reload Nginx with:
sudo systemctl reload nginx
Now go to your browser and access the application using the server’s domain name or IP address, as defined by the server_name directive in your configuration file:
http://server_domain_or_IP
by გიორგი ბაკაშვილი
4 years ago
0
Linux
Laravel
2
Create a New User and Grant Permissions in MySQL
log in with this command in terminal:
mysql -u [username] -p
making a new user within the MySQL shell
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
Therefore, the first thing to do is to provide the user with access to the information they will need.
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
Once you have finalized the permissions that you want to set up for your new users, always be sure to reload all the privileges.
FLUSH PRIVILEGES;
How To Grant Different User Permissions
Here is a short list of other common possible permissions that users can enjoy. ALL PRIVILEGES- as we saw previously, this would allow a MySQL user full access to a designated database (or if no database is selected, global access across the system) CREATE- allows them to create new tables or databases DROP- allows them to them to delete tables or databases DELETE- allows them to delete rows from tables INSERT- allows them to insert rows into tables SELECT- allows them to use the SELECT command to read through databases UPDATE- allow them to update table rows GRANT OPTION- allows them to grant or remove other users’ privileges To provide a specific user with a permission, you can use this framework:
To GRANT ALL
privileges to a user, allowing that user full control over a specific database, use the following syntax:
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
GRANT type_of_permission ON database_name.table_name TO 'username'@'localhost';
revoke a permission, the structure is almost identical to granting it:
REVOKE type_of_permission ON database_name.table_name FROM 'username'@'localhost';
review a user’s current permissions by running the following:
SHOW GRANTS FOR 'username'@'localhost';
delete databases with DROP, you can use DROP to delete a user altogether:
DROP USER 'username'@'localhost';
log out by typing:
quit
by გიორგი ბაკაშვილი
4 years ago
0
Linux
MySQL
2
Results: 1580