$text = 'Not enough data
jkl
Not enough data';
$total = preg_match_all('/Not enough data/', $text, $matches);
var_dump($total, $matches);
$text = 'Привет, [name] !';
$text = preg_replace('~\[name\]~', 'Имя', $text);
echo $text;
$text = 'Привет, [name] !';
$text = str_replace('[name]', 'Имя', $text);
echo $text;
$test_mass[] = [
"lesson_name" => "Установка",
"текст1",
"текст2",
"текст3"
];
$test_mass[] = [
"lesson_name" => "Виды настроек",
"текст4",
"текст5",
"текст6",
"текст7",
];
$out_text = '';
foreach ($test_mass as $mas) {
foreach ($mas as $key => $text) {
if ($key === 'lesson_name') {
$out_text .= '-';
}
$out_text .= $text . "</br>";
}
}
echo $out_text;
$string = " ~~~ любой текст ~~~ [token|234] ~~~ любой текст ~~~ ";
$string = preg_replace('~\[token\|\d+\]\h*~', '', $string);
echo $string;
$array = [
'premium contact',
'premium contact 2',
'premium3 contact 3',
'sport contact 2',
'sport vanco 2'
];
$result = [];
foreach ($array as $item) {
$key = substr($item, 0, 5);
$result[$key][] = $item;
}
$result = array_values($result);
print_r($result);
/*
Array
(
[0] => Array
(
[0] => premium contact
[1] => premium contact 2
[2] => premium3 contact 3
)
[1] => Array
(
[0] => sport contact 2
[1] => sport vanco 2
)
)
*/
к примеру сложить первые три индекса
$arr = [0 => 12, 1 => 15, 2 => 15, 3 => 75, 4 => 77, 5 => 40, 6 => 15, 7 => 2, 8 => 40, 9 => 11, 10 => 8];
$slice = array_slice($arr, 0, 3);
$result = array_sum($slice) / sizeof($slice);
echo $result;
чего-то типо[^\.js] пытался...
(?!css|js|png|ico|xml)