function cleanText(string $text) {
$cleaned = [];
foreach (str_split($text) as $i=>$letter) {
if ($letter === "&" || $text[$i-1] === "&") {
continue;
}
$cleaned[] = $letter;
}
return implode("", $cleaned);
}
function justify(string $someWord, string $otherWord) {
$spaces = "";
if (strlen($someWord) !== strlen($otherWord)) {
$diff = abs(mb_strlen($someWord)-mb_strlen($otherWord));
$offset = ceil($diff/2);
$spaces = str_repeat(" ", $offset);
}
if (mb_strlen($someWord) >= mb_strlen($otherWord)) {
return $someWord . PHP_EOL . $spaces . $otherWord;
} else {
return $spaces . $someWord . PHP_EOL . $otherWord;
}
}
$checkUser = mysqli_query($connect, "SELECT * FROM `users` WHERE `email` == '$email' AND `password` == '$password'");
if ($checkUser === false) {
die(mysqli_error($connect));
}
// БЕЗОПАСНО выполняем запрос
$stmt = $link->prepare("SELECT * FROM comments WHERE art_id = ?");
$stmt->bind_param("s", $note_id);
$stmt->execute();
// получаем данные
$result = $stmt->get_result();
$comments = $result->fetch_all(MYSQLI_ASSOC);
<?php if ($comments): ?>
<?php foreach ($comments as $row): ?>
<?=$row['comment']?><br>
<?php endforeach ?>
<?php else: ?>
Эту запись еще никто не комментировал
<?php endif ?>
$queryString = http_build_query($params);
$decodedQueryString = urldecode($queryString); // Не совсем понимаю, зачем эта операция вообще. Объясните, зачем вы это делаете
$requestUrl = "https://oauth.vk.com/access_token?{$decodedQueryString}";
$response = file_get_contents($requestUrl);
$userInfo = json_decode($response);
$json = '{"status":{"timestamp":"2021-05-03T16:47:16.362Z","error_code":0,"error_message":null,"elapsed":370,"credit_count":0,"notice":null},"data":{"2016-10-26T02:39:28.000Z":{"BTC":[1],"USD":[660.28167725,87283944,10525640015.288086]},"2016-10-27T02:39:28.000Z":{"BTC":[1],"USD":[702.39459229,89816296,11200777509.550781]}}}';
$data = json_decode($json, true);
foreach($data['data'] as $date=>$values) {
$date = date("Y-m-d H:i:s", strtotime($date));
$usd = $values['USD'][0] ?? null;
$usd_two = $values['USD'][1] ?? null;
$usd_three = $values['USD'][2] ?? null;
// Далее здесь можно вызвать функцию, которая сохранит значения в базу
}
$fromDb = [
['id'=>1, 'day'=>2, 'month'=>1],
['id'=>2, 'day'=>22, 'month'=>3],
['id'=>2, 'day'=>31, 'month'=>2],
['id'=>4, 'day'=>12, 'month'=>2],
['id'=>5, 'day'=>4, 'month'=>3]
];
function groupBy(array $elements, callable $getUniqueKey) {
$grouped = [];
foreach ($elements as $element) {
$uniqueKey = $getUniqueKey($element);
$grouped[$uniqueKey][] = $element;
}
return $grouped;
}
$groupedByMonth = groupBy($fromDb, function($row) {
return $row['month'];
});
$array = [
['text' => "Сегодня мы пошли с друзьями на речку."],
['text' => "Вчера мы ходили с самого утра по магазинам."],
['text' => "Сегодня мы гуляли возле большого парка."]
];
$string = implode(" ", array_column($array, "text"));
$lowercased = mb_strtolower($string);
$cleaned = preg_replace("/[^а-я ]/u", "", $lowercased);
$words = explode(" ", $cleaned);
$frequency = array_count_values($words);
SELECT
`trade_history`.`uf_date`
FROM
`information_schema`.`tables` AS `informationSchemaTable`
JOIN `dbname`.`trade_history` ON (`informationSchemaTable`.`auto_increment`-1=`trade_history`.`id`)
WHERE 1
AND `informationSchemaTable`.`table_schema` = 'dbname'
AND `informationSchemaTable`.`table_name` = 'trade_history'
if (!session_id()) {
session_start();
}
if (array_key_exists("PRICE", $_GET) && $_GET['PRICE'] === "Y") {
$_SESSION['PRICE'] = "Y";
}
if (array_key_exists("PRICE", $_SESSION) && $_GET['PRICE'] === "Y") {
// здесь код, специфичный для PRICE=Y в сессии
}
$file = new SplFileObject("file.txt", "r");
$file->seek(PHP_INT_MAX);
$lastLine = $file->key();
$lines = new LimitIterator($file, $lastLine-5, $lastLine);
var_dump(iterator_to_array($lines));
$encodedData = '{"result":[{"id":"103513","user":"user_repeat","time_upd":"2020-12-09 08:45:02"},{"id":"103517","user":"user_repeat","time_upd":"2020-12-09 08:45:02"},{"id":"103522","user":"user_no_repeat","time_upd":"2020-12-09 08:45:02"}]}';
$decodedData = json_decode($encodedData, true);
$userRepeats = [];
foreach ($decodedData['result'] as $info) {
if (!array_key_exists($info['user'], $userRepeats)) {
$userRepeats[$info['user']] = 0;
}
$userRepeats[$info['user']]++;
}
arsort($userRepeats);
$mexRepeatsUser = [key($userRepeats)=>current($userRepeats)];
var_dump($userRepeats);
var_dump($mexRepeatsUser);
$count = count($this->films_model->getFilms(0, 1));
$query = $this->db->get_where('movie', array('slug'=>$slug));
$count = count($this->films_model->getFilms(false, PHP_INT_MAX));
<?php $cf = get_post_meta(get_the_ID(), 'n', true);
<?php if (!empty($cf)) { ?>
<meta name="robots" content="noindex,follow"/>
<?php } ?>
<?php if ( is_search() || is_404() || in_category(3) || is_tag() || is_author() ) { ?>
<meta name="robots" content="noindex,follow" />
<?php } ?>
<meta property="og:description" content="<?= get_post_meta(get_the_ID(), 'd', true) ?>"/>
$connect = mysqli_connect("localhost", "root", "", "site");
$sql = "SELECT * FROM `users` WHERE `login` = ?";
$stmt = $connect ->prepare($sql);
$stmt->bind_param("s", $_POST['username']);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
echo 'This username is already taken';
} else {
echo 'This username is available';
}