$str = 'Текст, ещё текст ABCDEF ещё текст текст GHJKL -- много текста MNOP и напоследок снова ABCDEF конец';
$replaces = [['text' => 'ABCDEF', 'replace' => 'AAA', 'limit' => 1], ['text' => 'GHJKL', 'replace' => 'BBB'], ['text' => 'ABCDEF', 'replace' => 'CCC']];
foreach ($replaces as $replace){
$str = preg_replace('#' . $replace['text'] . '#', $replace['replace'], $str, ($replace['limit'] ?? -1));
}
echo $str;
Я их не хочу оставлять в public, чтобы к ним не было прямого доступа из браузера.
// PHP 7.4+
$first = current(array_filter(array($c1, $c2, $c3, $c4), fn($value) => !is_null($value) && $value !== '')));
Hi, did you found a solution for this problem?
upd:
Well, after hours of attempts I fixed it:
There could be few reasons:
Not enought permissions on operation folder (you need to put recousively 775 permission to make it work)
Check the owner and owner-group of this folder, maybe current user doesn't have permission to read/write in current folder, also could be fixed by providing extra permissions to folder (777)
Check your tmp folder, if it's also writable or not. In internet there are a lot of variants how to do it, in my case, I have just change path to tmp folder in vendor/phpoffice/phpword/src/Settings.php, function getTempDir(), I have hardcoded absolute path of current working directory and problem was gone. But probably it's not best idea.
if ($req[1]) $res['params']['lastname'] = $req[1]
if ($req[2]) $res['params']['firstname'] = $req[2]
if ($req[3]) $res['params']['secondname'] = $req[3]
if ($req[4]) $res['params']['birthdate'] = $req[4]
if ($req[5]) $res['params']['phone'] = $req[5]
if ($req[6]) $res['params']['email'] = $req[6]
$res['params']
, прежде чем отправлять на сторонний сервис:$res['params'] = array_filter($res['params'], function($v) { return !is_null($v); });
Текстовые поля у меня фильтруются все на вводе
https://simfershop.ru/catalog/varochnye-paneli/gazovye-varochnye-paneli/gazovaya-varochnaya-panel-simfer-h45v30b400-chugunnye-reshetki-s-avtopodzhigom-/?OFFER_ID=75336
https://simfershop.ru/catalog/varochnye-paneli/gazovye-varochnye-paneli/gazovaya-varochnaya-panel-simfer-h45v30b400-chugunnye-reshetki-s-avtopodzhigom-/?OFFER_ID=75337
public static function limit_words($str, $limit = 100, $end_char = NULL)
{
$limit = (int) $limit;
$end_char = ($end_char === NULL) ? '…' : $end_char;
if (trim($str) === '')
return $str;
if ($limit <= 0)
return $end_char;
preg_match('/^\s*+(?:\S++\s*+){1,'.$limit.'}/u', $str, $matches);
// Only attach the end character if the matched string is shorter
// than the starting string.
return rtrim($matches[0]).((strlen($matches[0]) === strlen($str)) ? '' : $end_char);
}
$request = "UPDATE products SET name = '$name', description = '$description', parameters = '$parameters', manufacturer = '$manufacturer', cost = '$cost' WHERE article = $article";
$request = "UPDATE products SET name = '$name', description = '$description', parameters = '$parameters', manufacturer = '$manufacturer', cost = '$cost' WHERE article = '$article'";
php -S localhost:8000
<link href=\"backend/design/css/print.css\" rel=\"stylesheet\" type=\"text/css\" />
error_reporting(E_ALL);
ini_set('display_startup_errors', 1);
ini_set('display_errors', '1');
function get_text($el) {
$text = "";
if ($el instanceof PhpOffice\PhpWord\Element\TextRun) {
foreach ($el->getElements() as $child) {
$text .= get_text($child);
}
} elseif ($el instanceof PhpOffice\PhpWord\Element\Text) {
$text .= $el->getText();
}
return $text;
}