<?php
$f = fopen("your.file", "r");
if ($f) {
$today = strtotime(date("Y-m-d"));
while (($line = fgets($f)) !== false) {
preg_match('/\d+\s(\d{2}\.\d{2}\.\d{4})/', $line, $m);
if ($m && strtotime($m[1]) < $today) {
echo $line . PHP_EOL;
}
}
fclose($f);
}
<?php
require "includes/config.php";
$articlesx = mysqli_query($connection, "SELECT * FROM `matem` ORDER BY `views` DESC LIMIT 8");
while($artx = mysqli_fetch_assoc($articlesx)) {
echo '<li><a href="#">'.$artx.'</a></li>';
}
echo '<li><a href="#">'.$artx['тут какой-то ключ'].'</a></li>';
select distinct year(d) from t;
<?php
$num = 12345678900000000;
$pow = floor(log10($num));
echo $num / pow(10, $pow) . ' * 10^'.$pow;
<?php
if (10 <= date("G") && date("G") <= 20) {
echo "сейчас на сервере от 10 до 20 часов.";
}
<?php
$commands = [
'hi' => fn($name) => 'hi, ' . $name,
'hello' => fn($name) => 'hello , ' . $name,
'etc' =>fn($name) => 'etc...',
];
echo $commands['hi']('John');
<?php
$arr = [1, 3, 4, 6, 4, 2, 1, 1];
$res1 = array_count_values($arr);
//var_export($res1);
$res2 = array_filter($res1, fn($el)=>($el>1));
var_export(array_keys($res2));
json_encode(
[ 'Цена' => intval($_GET['price'] * 100 )/100 ],
JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
);
<?php
$date = date('Y-m-01');
$next_month = date('Y-m-d', strtotime('+1 month', strtotime($date)));
function nextWorkDay($date) {
$day_of_week = date('N', strtotime($date));
if ($day_of_week>5) {
//echo "Weekend: " . $date;
$shift = 8-$day_of_week;
return date('Y-m-d', strtotime("+{$shift} day", strtotime($date)));
} else {
echo "Work day ($day_of_week):" . $date . PHP_EOL;
return date('Y-m-d', strtotime('+3 day', strtotime($date)));
}
}
while ($date < $next_month) {
$date = nextWorkDay($date);
}
create table user_balance (
user_id int,
balance decimal(9, 2) check (balance >=0)
);
create table user_balance_unsigned (
user_id int,
balance decimal(9, 2) unsigned
);
<?php
function myRound($n) {
$d = (int)log10($n) - 1;
return ceil($n/10**$d) * 10**$d;
}
<?php
$query = "SELECT COUNT(*) cnt FROM sakila.actor;";
// get DB version using PDO
$stmt = $pdo->prepare($query);
$stmt->execute();
$count = $stmt->fetchColumn();
printf("Count rows in table actor is: %d", $count);