$(document).on("click", "#form [type='submit']", function () {
var value = $("#form select option[selected]").text(); // Здесь будет ваш текст вида "Значение1".
// Дальше делаете с ним что вам нужно и отправляете данные себе на сервер.
});
$prepareString = new Twig_SimpleFunction('prepareString', function ($str) {
return str_replace("%param1%", "Тест", $str);
});
$twig->addFunction($prepareString);
<span>{{ prepareString("Ваша строка с '%param1%'") }}</span>
$pattern = "/=icon:((#|\.\w+)|):((\w+)\.(\w+))/";
$callback = function ($m) {
return trim($m);
};
echo preg_replace_callback($pattern, $callback, '=icon:#logotype_mini:logotype_mini.svg');
function response($data = []) {
header("Content-Type: application/json; charset=utf-8");
$flags = JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_PRETTY_PRINT;
$fails = implode('|', array_filter([
'\\\\',
$flags & JSON_HEX_TAG ? 'u003[CE]' : '',
$flags & JSON_HEX_AMP ? 'u0026' : '',
$flags & JSON_HEX_APOS ? 'u0027' : '',
$flags & JSON_HEX_QUOT ? 'u0022' : '',
]));
$pattern = "/\\\\(?:(?:$fails)(*SKIP)(*FAIL)|u([0-9a-fA-F]{4}))/";
$callback = function ($m) {
return html_entity_decode("&#x$m[1];", ENT_QUOTES, 'UTF-8');
};
echo preg_replace_callback($pattern, $callback, json_encode($data, $flags));
exit;
}
response([ "a" => "b", ]);
$.post('/some_page.php?', post).done(function (response) {
// обработчик json, в переменной response сразу распарсенный объект благодаря заголовку Content-Type: application/json
}).fail(function(xhr, status, error) {
console.error(error); // обработчик ошибки ответа сервера
});
$errors = array();
function test(){
global $errors;
return $errors[] = 'empty_test';
}
test();
print_r($errors);
$errors = array();
function test() {
global $errors;
$test = 'empty_test';
$errors[] = $test;
return $test;
}
test();
print_r($errors);
Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /var/www/u0294446/public_html/development/inquiry_photo.php on line 22
Warning: imagecreatefromjpeg(): '78.jpeg' is not a valid JPEG file in /var/www/u0294446/public_html/development/inquiry_photo.php on line 22
Warning: imagecopy() expects parameter 2 to be resource, boolean given in /var/www/u0294446/public_html/development/inquiry_photo.php on line 34
\DateTime::createFromFormat("d.m.Y в H:i", $dateStr);
$lexems = [
"text" => "TEXT",
];
$data = [];
foreach ($_REQUEST as $k => $v) {
if (array_key_exists($k, $lexems)) {
$data[$k] => htmlspecialchars(trim($v));
}
}
$sourceText = file_get_contents("/path/to/template.txt");
foreach ($data as $k => $v) {
$sourceText = str_replace('{' . $lexems[$k] . '}', $v, $sourceText);
}
echo $sourceText;
$show_info = fopen('events/kp1/dungeon1.txt', 'r');
fgets($show_info);
echo fgets($show_info);
fclose($show_info);
function readLine($pathToFile, $index = 0) {
if (!file_exists($pathToFile)) {
return null;
}
$stream = fopen($pathToFile, 'r');
$line = null;
for ($i = 0; $i <= $index; $i++) {
if ($index > 0) {
fgets($stream);
}
if ($i == $index) {
$line = fgets($stream);
}
}
fclose($stream);
return $line;
}
echo readLine('events/kp1/dungeon1.txt', 1); // Выведет вторую строку файла.
class Hook {
protected $callbacks;
public function __construct($callbacks = []) {
$this->callbacks = [];
if (!isset($callbacks) || !is_array($callbacks) || sizeof($callbacks)) {
return;
}
foreach ($callbacks as $k => $v) {
if (!is_string($k) || !isset($v) || !is_callable($v)) {
continue;
}
$this->callbacks[$k] = $v;
}
}
public function add($key, $callback) {
if (!isset($key) || !isset($callback) || !is_string($key) || !is_callable($callback)) {
return;
}
$this->callbacks[$key] = $callback;
}
public function remove($key) {
if ($this->exists($key)) {
unset($this->callbacks[$key]);
}
}
public function exists($key) {
return isset($key) && array_key_exists($key, $this->callbacks);
}
public function run($key, ...$args) {
if ($this->exists($key)) {
$func = $this->callbacks[$key];
if (!isset($args) || !is_array($args)) {
$args = [];
}
if (isset($func)) {
$func(...$args);
}
}
}
}
$hook = new Hook();
$hook->add("my_hook", function ($args) {
// todo
});
$hook->run("my_hook");
$hook->run("my_hook", 1, "string", true);