Answer the question
In order to leave comments, you need to log in
Replace in text but skip replacement in tags?
There is a code like this replaces once in the text:
function str_replace_once($search, $replace, $text)
{
$pos = strpos($text, $search);
return $pos!==false ? substr_replace($text, $replace, $pos, strlen($search)) : $text;
}
$str = 'Helo World!';
$str = str_replace_once('l', 'll', $str);
// результат 'Hello World!';
$str = '<a href="(тут любая ссылка)">Helo World!</a>';
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question