$string = 'Задолженность: 1138509.21 руб. Исполнительский сбор: 79695.67 руб.';
$dolg = $sbor = null;
if(preg_match_all('/([0-9]*[.])?[0-9]+/uis', $string, $matches)) {
[$dolg, $sbor] = $matches[0];
}
public function index()
{
$categories = ...;
echo self::getTree($categories);
}
public static function getTree($categories, $parent_id = 0) // или null, смотря что по дефолту
{
$result = '';
foreach ($categories as $category) {
if ($category->parent != $parent_id) {
continue;
}
$result .= sprintf('<li><a>%s</a>%s</li>',
$category->name,
self::getTree($categories, $category->categories_id) // или $category->id, смотря где там id
);
}
return $result ? sprintf('<ul>%s</ul>', $result) : '';
}
$string = '
https://clips.twitch.tv/SneakyFantasticMoonLitty123
или так
https://www.twitch.tv/lex4tor88/clip/SneakyFantasticMoonLitty456?filter=clips&range=all&sort=time
';
if(preg_match_all('/twitch\.tv\/(?:[^\/]+\/clip\/)?([0-9a-z]+)/uis', $string, $matches)) {
print_r($matches[1]);
}
return preg_replace('/<p([^>]+)?>(?!.*<p)/s', '<p$1 class="class">', $content, 1);
<button type="submit" name="a" value="1">Отправить 1</button>
<button type="submit" name="b" value="2">Отправить 2</button>
не нравится? preg_replace_callback('/(.{0,1})"(.*?)"(.{0,1})/uis', function ($matches) {
$result = strlen($matches[1]) && $matches[1] != ' ' ? $matches[1] . ' ' : $matches[1];
$result .= sprintf('"%s"', trim($matches[2]));
$result .= strlen($matches[3]) && !preg_match("/[-.?!)(,: ]/uis", $matches[3]) ? ' ' . $matches[3] : $matches[3];
return $result;
}, $str);