A
A
Alexey selftrips.ru2020-05-23 19:19:31
PHP
Alexey selftrips.ru, 2020-05-23 19:19:31

How to find in the text and highlight a certain letter at the beginning of words (php, regex)?

For example me". Big or small - it doesn't matter, but they should remain the same.
Apple pit wash -> I blocko I ma wash

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2020-05-23
@rpsv

$re = '/(\w+?)(?:[^\w]|$)/siu';
$str = preg_replace_callback($re, function($m) {
    return "<span class='red'>". mb_substr($m[1], 0, 1) ."</span>". mb_substr($m[1], 1);
}, $str );

D
dodo512, 2020-05-23
@dodo512

$str = ' Яблоко яма умываться ';

echo preg_replace('/\bЯ/iu', '<b>$0</b>', $str);

echo preg_replace('/(?<!\w)Я/iu', '<b>$0</b>', $str);

echo preg_replace('/Я/iu', '<b>$0</b>', $str);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question