php://input
// твои данные тут
$input = json_decode(file_get_contents("php://input"), true);
/width:[0-9]*px;/
class Str {
private $string = "";
public function __construct($string = "") {
$this->string = strval($string);
}
public function __toString() {
return $this->string;
}
public function length() {
return mb_strlen($this->string);
}
public function substr($start, $length = null) {
return new static(mb_substr($this->string, $start, $length));
}
}
$string = new Str("qwertyuiop");
echo $string . "\n";
echo $string->length() . "\n";
echo $string->substr(-3) . "\n";
class Sql {
public function query() {
....
return new SqlResult($stmt);
}
}
class SqlResult {
public function __constructor($stmt) {
$this->stmt = $stmt;
}
public function getCollumns() {
return $this->stmt->fetchColumn();
}
public function getRows() {
return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
ini_set('mssql.charset', 'UTF-8');
$res = query("
SELECT * FROM TableA
SELECT * FROM TableB
....
");
fetch($res); // tableA rows
next($res); // switch to next result
fetch($res); // tableB rows
$rows = file('myfile.txt');
$data = [];
foreach($rows as $row) {
list($key, $value) = explode(' ', $row);
$$key = $value;
}
echo $minland; // 678678
echo $maxland; // 678678
echo $minvisitka; // 589
function replace_unicode_escape_sequence($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}
function unicode_decode($str) {
return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $str);
}
echo unicode_decode("\u041f\u0435\u0440\u0432\u044b\u0439 \u043e\u0442\u0447\u0435\u0442");
class Finder {
public static function find($func) {
return file_get_contents("https://www.php.net/manual/ru/function.{$func}.php");
}
}
file_get_contents("https://www.php.net/search.php?show=quickref&pattern={$func}");
class Finder {
public static function find($func) {
$url = "https://www.php.net/search.php";
return file_get_contents($url . http_build_query([
"show" => "quickref",
"pattern" => $func
]));
}
}
$_GET["page"] = "12";
$page = 0;
$numRows = 122;
$rowsPerPage = 5;
$plus = 2;
if (isset($_GET["page"]) && $_GET["page"] > 0) {
$page = intval($_GET["page"]);
}
$maxPage = ceil($numRows / $rowsPerPage);
if ($page - $plus > 0) {
echo "< ";
}
for ($i = $page - $plus; $i <= $page + $plus; $i++) {
if ($i < 0) continue;
if ($i > $maxPage) break;
echo $i . " ";
}
if ($page + $plus < $maxPage) {
echo ">";
}
mb_substr($txt, $i, 1, "UTF-8")
. Попутно открываешь для себя многобайтные кодировки и функции для работы с ними, с префиксом mb_. Длину строки получаешь вот так: mb_strlen($name, "UTF-8")
$str = "привет бла бла бла";
echo strlen($str); // 33 wrong
echo mb_strlen($str); // 18 ok
echo $str[0]; // wrong
echo substr($str, 0, 1); // wrong
echo mb_substr($str, 0, 1); // ok
function BuildGetHashtagInfoQuery($id = null, $tag = null, $type = null) {
$sql = "SELECT * FROM `hashtags`";
$where = [];
if (is_numeric($id)) {
$where["id"] = $id;
}
if (is_string($tag)) {
$where["tag"] = $tag;
}
if (is_string($type)) {
$where["type"] = $type;
}
if (count($where) > 0) {
$sql .= " WHERE ";
$sql .= implode(" AND ", array_map(function($key) use($where) {
return "`{$key}` = '{$where[$key]}'";
}, array_keys($where)));
}
return $sql;
}
echo BuildGetHashtagInfoQuery(123, "cat", "animal");
async function update() {
try {
const name = encodeURIComponent(document.getElementById("Name").value);
const response = await fetch("ajax.php?name=" + name);
const text = await response.text();
document.getElementById("OurMessage").innerHTML = '<i>' + text+ '<i>';
}
catch (err) {
console.warn(err);
}
setTimeout(async () => await update(), 1000);
}
(async () => {
await update();
})();